11 EngeCoefs_entry_m(NULL),
12 EngeCoefs_exit_m(NULL),
16 cosExitRotation_m(1.0),
17 sinExitRotation_m(0.0) {
20 std::string tmpString;
28 bool parsing_passed = \
29 interpretLine<std::string, int, int, double>(file,
34 parsing_passed = parsing_passed &&
35 interpretLine<double, double, double, int>(file,
40 parsing_passed = parsing_passed &&
41 interpretLine<double, double, double, int>(file,
46 for (
int i = 0; (i < num_gridpz + 1) && parsing_passed; ++ i) {
47 parsing_passed = parsing_passed &&
48 interpretLine<double>(file, tmpDouble);
51 parsing_passed = parsing_passed &&
57 if (!parsing_passed) {
91 double tolerance = 1
e-8;
96 std::string tmpString;
99 double minValue = 99999999.99, maxValue = -99999999.99;
101 int num_gridp_fringe_entry, num_gridp_fringe_exit;
102 int num_gridp_before_fringe_entry, num_gridp_before_fringe_exit;
104 double *rightHandSide;
105 double *leastSquareMatrix;
108 interpretLine<std::string, int, int, double>(in, tmpString, tmpInt, tmpInt, tmpDouble);
109 interpretLine<double, double, double, int>(in, tmpDouble, tmpDouble, tmpDouble, num_gridpz);
110 interpretLine<double, double, double, int>(in, tmpDouble, tmpDouble, tmpDouble, tmpInt);
117 RealValues =
new double[num_gridpz + 1];
119 for (
int i = 0; i < num_gridpz + 1; ++i) {
120 interpretLine<double>(in, RealValues[i]);
121 if (RealValues[i] > maxValue) maxValue = RealValues[i];
122 else if (RealValues[i] < minValue) minValue = RealValues[i];
127 for (
int i = 0; i < num_gridpz + 1; ++i)
128 RealValues[i] = (RealValues[i] - minValue) / (maxValue - minValue);
132 while(i < num_gridpz + 1 && RealValues[i] < tolerance) ++i;
133 num_gridp_before_fringe_entry = i - 1;
136 while(i < num_gridpz + 1 && RealValues[i] < 1. - tolerance) ++i;
137 num_gridp_fringe_entry = i - 1 - num_gridp_before_fringe_entry;
140 while(i < num_gridpz + 1 && RealValues[i] >= 1. - tolerance) ++i;
141 num_gridp_before_fringe_exit = i - 1;
143 while(i < num_gridpz + 1 && RealValues[i] > tolerance) ++i;
144 num_gridp_fringe_exit = i - 1 - num_gridp_before_fringe_exit;
148 int num_gridp_fringe =
std::max(num_gridp_fringe_entry, num_gridp_fringe_exit);
150 leastSquareMatrix =
new double[(polynomialOrder + 1) * num_gridp_fringe];
151 rightHandSide =
new double[num_gridp_fringe];
155 for (
int i = 0; i < num_gridp_fringe_entry; ++i) {
156 double powerOfZ = 1.;
158 rightHandSide[i] =
log(1. / RealValues[num_gridp_before_fringe_entry + i + 1] - 1.);
168 for (
int i = 0; i < num_gridp_fringe_exit; ++i) {
169 double powerOfZ = 1.;
171 rightHandSide[i] =
log(1. / RealValues[num_gridp_before_fringe_exit + i + 1] - 1.);
185 delete[] leastSquareMatrix;
186 delete[] rightHandSide;
241 double S = EngeCoefs[polynomialOrder] * z;
242 S += EngeCoefs[polynomialOrder - 1];
243 double dSdz = polynomialOrder * EngeCoefs[polynomialOrder];
245 for (
int i = polynomialOrder - 2; i >= 0; i--) {
246 S = S * z + EngeCoefs[i];
247 dSdz = dSdz * z + (i + 1) * EngeCoefs[i + 1];
248 d2Sdz2 = d2Sdz2 * z + (i + 2) * (i + 1) * EngeCoefs[i + 2];
251 double f = 1.0 / (1.0 + expS);
254 double dfdz = - f * ((f * expS) * dSdz);
257 double d2fdz2 = ((-d2Sdz2 - dSdz * dSdz * (1. - 2. * (expS * f))) * (f * expS) * f) / (
gapHeight_m *
gapHeight_m);
261 strength(2) = d2fdz2;
365 void solve(
double *
Matrix,
double *Solution,
double *rightHandSide,
const int &M,
const int &N) {
370 double *
R =
new double[M * N];
371 double *tempVector =
new double[M];
372 double *residuum =
new double[M];
374 for (
int i = 0; i < M; ++i) {
375 for (
int j = 0; j < N; ++j)
376 R[i * N + j] =
Matrix[i * N + j];
377 tempVector[i] = rightHandSide[i];
381 for (
int i = 0; i < N; ++i) {
382 for (
int j = i + 1; j < M; ++j) {
383 len =
std::sqrt(
R[j * N + i] *
R[j * N + i] +
R[i * (N + 1)] *
R[i * (N + 1)]);
384 sinphi = -
R[j * N + i] / len;
385 cosphi =
R[i * (N + 1)] / len;
387 for (
int k = 0; k < N; ++k) {
388 tempValue = cosphi *
R[ i * N + k] - sinphi *
R[ j * N + k];
389 R[j * N + k] = sinphi *
R[ i * N + k] + cosphi *
R[ j * N + k];
390 R[i * N + k] = tempValue;
398 for (
int i = 0; i < N; ++i) {
400 for (
int j = 0; j < M; ++j) {
401 tempValue +=
Matrix[j * N + i] * rightHandSide[j];
403 Solution[i] = tempValue;
406 for (
int i = 0; i < N; ++i) {
408 for (
int j = 0; j < i; ++j)
409 tempValue +=
R[j * N + i] * residuum[j];
410 residuum[i] = (Solution[i] - tempValue) /
R[i * (N + 1)];
413 for (
int i = N - 1; i >= 0; --i) {
415 for (
int j = N - 1; j > i; --j)
416 tempValue +=
R[i * N + j] * Solution[j];
417 Solution[i] = (residuum[i] - tempValue) /
R[i * (N + 1)];
420 for (
int i = 0; i < M; ++i) {
422 for (
int j = 0; j < N; ++j)
423 tempValue +=
Matrix[i * N + j] * Solution[j];
424 residuum[i] = rightHandSide[i] - tempValue;
427 for (
int i = 0; i < N; ++i) {
429 for (
int j = 0; j < M; ++j)
430 tempValue +=
Matrix[j * N + i] * residuum[j];
431 tempVector[i] = tempValue;
434 for (
int i = 0; i < N; ++i) {
436 for (
int j = 0; j < i; ++j)
437 tempValue +=
R[j * N + i] * residuum[j];
438 residuum[i] = (tempVector[i] - tempValue) /
R[i * (N + 1)];
441 for (
int i = N - 1; i >= 0; --i) {
443 for (
int j = N - 1; j > i; --j)
444 tempValue +=
R[i * N + j] * tempVector[j];
445 tempVector[i] = (residuum[i] - tempValue) /
R[i * (N + 1)];
446 Solution[i] += tempVector[i];
Tps< T > log(const Tps< T > &x)
Natural logarithm.
Tps< T > cos(const Tps< T > &x)
Cosine.
Tps< T > exp(const Tps< T > &x)
Exponential.
Tps< T > sin(const Tps< T > &x)
Sine.
Tps< T > sqrt(const Tps< T > &x)
Square root.
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Inform & endl(Inform &inf)
Inform & level3(Inform &inf)
void solve(double *Matrix, double *Solution, double *rightHandSide, const int &M, const int &N)
constexpr double e
The value of.
bool interpreteEOF(std::ifstream &in)
void disableFieldmapWarning()
static std::string typeset_msg(const std::string &msg, const std::string &title)
double cosExitRotation_m
Cos and sin of the exit edge rotation with respect to the local coordinates.
double polynomialOrigin_entry_m
double * EngeCoefs_entry_m
virtual double getFrequency() const
double polynomialOrigin_exit_m
FM1DProfile2(std::string aFilename)
int polynomialOrder_entry_m
virtual void setFrequency(double freq)
double * EngeCoefs_exit_m
int polynomialOrder_exit_m
virtual bool getFieldstrength(const Vector_t &X, Vector_t &strength, Vector_t &info) const
virtual bool getFieldDerivative(const Vector_t &X, Vector_t &E, Vector_t &B, const DiffDirection &dir) const
virtual void setEdgeConstants(const double &bendAngle, const double &entranceAngle, const double &exitAngle)
virtual void getFieldDimensions(double &zBegin, double &zEnd) const
virtual void setExitFaceSlope(const double &)
virtual void getInfo(Inform *)
Vektor< double, 3 > Vector_t