本文整理汇总了C++中Twiss类的典型用法代码示例。如果您正苦于以下问题:C++ Twiss类的具体用法?C++ Twiss怎么用?C++ Twiss使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Twiss类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Twiss
MapBeamLine::MapBeamLine(string filename, string filenameerr, int order, int nbthreads, int fmultipole, bool strpl) {
Twiss t = Twiss(filename);
Twiss terr = Twiss(filenameerr);
if (strpl) {
t.stripLine();
terr.stripLine();
}
omp_set_num_threads(nbthreads);
vector<vector<Polynom<double>>> v = separateComplexList(EQ(4, order));
Polynom<double> x = X<double>(order);
Polynom<double> px = PX<double>(order);
Polynom<double> y = Y<double>(order);
Polynom<double> py = PY<double>(order);
Polynom<double> d = D<double>(order);
Polynom<double> s = S<double>(order);
Polmap<double> R = generateDefaultMap(x, px, y, py, d, s);
Polmap<double>* Res = new Polmap<double>[nbthreads];
for (int i = 0; i < nbthreads; i ++)
Res[i] = R;
int size = t.elems.size();
Polmap<double>* mp = new Polmap<double>[size];
#pragma omp parallel for shared(Res) schedule(dynamic, CHUNK_SIZE)
for (int i = 0; i < size; i ++)
mp[i] = mapForElement(t.elems[i], v, x, px, y, py, d, s, fmultipole);
if (strpl) {
#pragma omp parallel for shared(Res) schedule(static)
for (int i = 0; i < size; i ++) {
int index = omp_get_thread_num();
double dx = atof(terr.elems[i][DX].c_str());
double dy = atof(terr.elems[i][DY].c_str());
mp[i] = mp[i].eval("x", Polynom<double>(order, 1E-18, "x", 1) + dx);
mp[i] = mp[i].eval("y", Polynom<double>(order, 1E-18, "y", 1) + dy);
Res[index] = mp[i] * Res[index];
}
}
else {
#pragma omp parallel for shared(Res) schedule(static)
for (int i = 0; i < size; i ++) {
int index = omp_get_thread_num();
double dx = atof(terr.elems[i][DX].c_str());
double dy = atof(terr.elems[i][DY].c_str());
mp[i] = mp[i].eval("x", Polynom<double>(order, 1E-18, "x", 1) + dx);
mp[i] = mp[i].eval("y", Polynom<double>(order, 1E-18, "y", 1) + dy);
if (mp[i].pols.size() != 0)
Res[index] = mp[i] * Res[index];
}
}
R = Res[0];
for (int i = 1; i < nbthreads; i ++)
R = Res[i] * R;
polmap = R.getMap();
for (unordered_map<string, Polynom<double>>:: iterator it = R.pols.begin(); it != R.pols.end(); it ++)
pols[it->first] = it->second;
delete [] Res;
delete [] mp;
}
示例2: cudaGetDevice
MapBeamLine::MapBeamLine(Twiss t, Twiss terr, int order, int nbthreads, int fmultipole, bool strpl) {
omp_set_num_threads(nbthreads);
cudaError_t error;
int devID = 0;
error = cudaGetDevice(&devID);
if (strpl) {
t.stripLine();
terr.stripLine();
}
vector<vector<Polynom<double>>> v = separateComplexList(EQ(4, order));
Polynom<double> x = X<double>(order);
Polynom<double> px = PX<double>(order);
Polynom<double> y = Y<double>(order);
Polynom<double> py = PY<double>(order);
Polynom<double> d = D<double>(order);
Polynom<double> s = S<double>(order);
Polmap<double> R = generateDefaultMap(x, px, y, py, d, s);
//alloc memory for arrays which will be transfered to/from the GPU
int nvars = 6;
int* exp_A = allocExponentsMemory(SIZE, nvars);
int* exp_B = allocExponentsMemory(SIZE, nvars);
int* exp_C = allocExponentsMemory(SIZE * SIZE, nvars);
double* coeff_A = allocCoefficientsMemory(SIZE);
double* coeff_B = allocCoefficientsMemory(SIZE);
double* coeff_C = allocCoefficientsMemory(SIZE * SIZE);
Polmap<double>* Res = new Polmap<double>[nbthreads];
for (int i = 0; i < nbthreads; i ++)
Res[i] = R;
int size = t.elems.size();
Polmap<double>* mp = new Polmap<double>[size];
#pragma omp parallel for shared(Res) schedule(dynamic, CHUNK_SIZE)
for (int i = 0; i < size; i ++)
mp[i] = mapForElement(t.elems[i], v, x, px, y, py, d, s, fmultipole);
if (strpl) {
#pragma omp parallel for shared(Res) schedule(static)
for (int i = 0; i < size; i ++) {
int index = omp_get_thread_num();
double dx = atof(terr.elems[i][DX].c_str());
double dy = atof(terr.elems[i][DY].c_str());
mp[i] = mp[i].eval("x", Polynom<double>(order, 1E-18, "x", 1) + dx);
mp[i] = mp[i].eval("y", Polynom<double>(order, 1E-18, "y", 1) + dy);
Res[index] = mp[i] * Res[index];
}
}
else {
#pragma omp parallel for shared(Res) schedule(static)
for (int i = 0; i < size; i ++) {
int index = omp_get_thread_num();
double dx = atof(terr.elems[i][DX].c_str());
double dy = atof(terr.elems[i][DY].c_str());
mp[i] = mp[i].eval("x", Polynom<double>(order, 1E-18, "x", 1) + dx);
mp[i] = mp[i].eval("y", Polynom<double>(order, 1E-18, "y", 1) + dy);
if (mp[i].pols.size() != 0)
Res[index] = mp[i] * Res[index];
}
}
R = Res[0];
for (int i = 1; i < nbthreads; i ++)
R = compose(Res[i], R, exp_C, exp_A, exp_B, coeff_C, coeff_A, coeff_B);
polmap = R.getMap();
for (unordered_map<string, Polynom<double>>:: iterator it = R.pols.begin(); it != R.pols.end(); it ++)
pols[it->first] = it->second;
delete [] Res;
delete [] mp;
freeMemory(exp_A, coeff_A);
freeMemory(exp_B, coeff_B);
freeMemory(exp_C, coeff_C);
cudaDeviceReset();
}