OSHUN  beta
Arbitrary Order Spherical-Harmonic 1D-3P Vlasov-Fokker-Planck-Maxwell code
setup.cpp
Go to the documentation of this file.
1 
10 // Standard libraries
11 #include <iostream>
12 #include <vector>
13 #include <valarray>
14 #include <complex>
15 #include <algorithm>
16 #include <cstdlib>
17 #include <cfloat>
18 
19 #include <math.h>
20 #include <map>
21 
22 // My libraries
23 #include "lib-array.h"
24 #include "lib-algorithms.h"
25 #include "exprtk.hpp"
26 
27 // Declerations
28 #include "input.h"
29 #include "state.h"
30 #include "formulary.h"
31 #include "setup.h"
32 // #include "parallel.h"
33 
34 
35 //**************************************************************
36 //**************************************************************
37 // INITIALIZATION
38 //**************************************************************
39 //**************************************************************
40 // void Setup_Y::prepare(Grid_Info &grid, State1D& Y)
41 // {
42 // parseprofile(grid.axis.x(0), Input::List().Ex_profile_str, Input::List().Ex_profile);
43 // parseprofile(grid.axis.x(0), Input::List().Ey_profile_str, Input::List().Ey_profile);
44 // parseprofile(grid.axis.x(0), Input::List().Ez_profile_str, Input::List().Ez_profile);
45 // parseprofile(grid.axis.x(0), Input::List().Bx_profile_str, Input::List().Bx_profile);
46 // parseprofile(grid.axis.x(0), Input::List().By_profile_str, Input::List().By_profile);
47 // parseprofile(grid.axis.x(0), Input::List().Bz_profile_str, Input::List().Bz_profile);
48 // }
49 //**************************************************************
50 //--------------------------------------------------------------
51 void Setup_Y::applyexternalfields(Grid_Info &grid, State1D& Y, double time)
52 {
53 
54  valarray<double> Ex_profile( grid.axis.Nx(0));
55  valarray<double> Ey_profile( grid.axis.Nx(0));
56  valarray<double> Ez_profile( grid.axis.Nx(0));
57  valarray<double> Bx_profile( grid.axis.Nx(0));
58  valarray<double> By_profile( grid.axis.Nx(0));
59  valarray<double> Bz_profile( grid.axis.Nx(0));
60 
61  double ex_time_coeff(0.0);
62  double ey_time_coeff(0.0);
63  double ez_time_coeff(0.0);
64  double bx_time_coeff(0.0);
65  double by_time_coeff(0.0);
66  double bz_time_coeff(0.0);
67 
68  parseprofile(grid.axis.x(0), Input::List().ex_profile_str, Ex_profile);
69  parseprofile(grid.axis.x(0), Input::List().ey_profile_str, Ey_profile);
70  parseprofile(grid.axis.x(0), Input::List().ez_profile_str, Ez_profile);
71  parseprofile(grid.axis.x(0), Input::List().bx_profile_str, Bx_profile);
72  parseprofile(grid.axis.x(0), Input::List().by_profile_str, By_profile);
73  parseprofile(grid.axis.x(0), Input::List().bz_profile_str, Bz_profile);
74 
75  parseprofile(time, Input::List().ex_time_profile_str, ex_time_coeff);
76  parseprofile(time, Input::List().ey_time_profile_str, ey_time_coeff);
77  parseprofile(time, Input::List().ez_time_profile_str, ez_time_coeff);
78  parseprofile(time, Input::List().bx_time_profile_str, bx_time_coeff);
79  parseprofile(time, Input::List().by_time_profile_str, by_time_coeff);
80  parseprofile(time, Input::List().bz_time_profile_str, bz_time_coeff);
81 
82  for (size_t ix(0);ix<Y.SH(0,0,0).numx();++ix)
83  {
84  if (ex_time_coeff > 1e-20) Y.EMF().Ex()(ix) = Ex_profile[ix]*ex_time_coeff;
85  if (ey_time_coeff > 1e-20) Y.EMF().Ey()(ix) = Ey_profile[ix]*ey_time_coeff;
86  if (ez_time_coeff > 1e-20) Y.EMF().Ez()(ix) = Ez_profile[ix]*ez_time_coeff;
87  if (bx_time_coeff > 1e-20) Y.EMF().Bx()(ix) = Bx_profile[ix]*bx_time_coeff;
88  if (by_time_coeff > 1e-20) Y.EMF().By()(ix) = By_profile[ix]*by_time_coeff;
89  if (bz_time_coeff > 1e-20) Y.EMF().Bz()(ix) = Bz_profile[ix]*bz_time_coeff;
90 
91  }
92 }
93 //---------------------------------------------------------------------------
94 //---------------------------------------------------------------------------
95 void Setup_Y::applytravelingwave(Grid_Info &grid, State1D& Y, double time)
96 {
97 
98  for (size_t n(0); n < Input::List().num_waves; ++n)
99  {
100 
101  valarray<double> Ex_profile( grid.axis.Nx(0));
102  valarray<double> Ey_profile( grid.axis.Nx(0));
103  valarray<double> Ez_profile( grid.axis.Nx(0));
104  valarray<double> Bx_profile( grid.axis.Nx(0));
105  valarray<double> By_profile( grid.axis.Nx(0));
106  valarray<double> Bz_profile( grid.axis.Nx(0));
107 
108 
110  parsetwovariableprofile(grid.axis.x(0), time, Input::List().ex_wave_profile_str[n], Ex_profile);
111  parsetwovariableprofile(grid.axis.x(0), time, Input::List().ey_wave_profile_str[n], Ey_profile);
112  parsetwovariableprofile(grid.axis.x(0), time, Input::List().ez_wave_profile_str[n], Ez_profile);
113  parsetwovariableprofile(grid.axis.x(0), time, Input::List().bx_wave_profile_str[n], Bx_profile);
114  parsetwovariableprofile(grid.axis.x(0), time, Input::List().by_wave_profile_str[n], By_profile);
115  parsetwovariableprofile(grid.axis.x(0), time, Input::List().bz_wave_profile_str[n], Bz_profile);
116 
117  double time_coeff(-1.0);
118 
119  // parseprofile(time, Input::List().wave_time_envelope_str[n], time_coeff);
120 
121  double pulse_start(Input::List().trav_wave_center[n] -
122  Input::List().trav_wave_flat[n]*0.5 -
123  Input::List().trav_wave_rise[n] );
124 
125  double pulse_end(Input::List().trav_wave_center[n] +
126  Input::List().trav_wave_flat[n]*0.5 +
127  Input::List().trav_wave_fall[n] );
128 
129  double normalized_time(0.0);
130 
131  // std::cout << "\n pulse_start, end = " << pulse_start << "," << pulse_end;
132 
133 
134  if (time >= pulse_start && time <= pulse_end)
135  {
136  if (time < Input::List().trav_wave_center[n] - 0.5*Input::List().trav_wave_flat[n])
137  {
138  normalized_time = (time - pulse_start)/ Input::List().trav_wave_rise[n];
139 
140  time_coeff = 6.0 * pow(normalized_time,5.0);
141  time_coeff -= 15.0 * pow(normalized_time,4.0);
142  time_coeff += 10.0 * pow(normalized_time,3.0);
143  }
144  else if (time >= Input::List().trav_wave_center[n] - 0.5*Input::List().trav_wave_flat[n] &&
145  time <= Input::List().trav_wave_center[n] + 0.5*Input::List().trav_wave_flat[n])
146  {
147  time_coeff = 1.0;
148  }
149  else if (time > Input::List().trav_wave_center[n] + 0.5*Input::List().trav_wave_flat[n])
150  {
151  normalized_time = (time - (Input::List().trav_wave_center[n] + 0.5*Input::List().trav_wave_flat[n]))
152  / Input::List().trav_wave_fall[n];
153 
154  time_coeff = 15.0 * pow(normalized_time,4.0);
155  time_coeff -= 6.0 * pow(normalized_time,5.0);
156  time_coeff -= 10.0 * pow(normalized_time,3.0);
157  time_coeff += 1.0;
158  }
159  }
160 
161  if (time_coeff > 0.0)
162  {
163  for (size_t ix(0);ix<Y.SH(0,0,0).numx();++ix)
164  {
165  Y.EMF().Ex()(ix) += Ex_profile[ix]*time_coeff;
166  Y.EMF().Ey()(ix) += Ey_profile[ix]*time_coeff;
167  Y.EMF().Ez()(ix) += Ez_profile[ix]*time_coeff;
168  Y.EMF().Bx()(ix) += Bx_profile[ix]*time_coeff;
169  Y.EMF().By()(ix) += By_profile[ix]*time_coeff;
170  Y.EMF().Bz()(ix) += Bz_profile[ix]*time_coeff;
171  }
172  }
173  }
174 }
175 //**************************************************************
176 //--------------------------------------------------------------
178 //--------------------------------------------------------------
179 // Initialization of the harmonics and the fields
180 //--------------------------------------------------------------
181 
182  Y = 0.0;
183 
184  valarray<double> dens_profile( grid.axis.Nx(0));
185  valarray<double> temp_profile( grid.axis.Nx(0));
186  valarray<double> f10x_profile( grid.axis.Nx(0));
187  valarray<double> f20x_profile( grid.axis.Nx(0));
188  valarray<double> pedestal_profile( grid.axis.Nx(0));
189 
190  valarray<double> hydro_dens_profile( grid.axis.Nx(0));
191  valarray<double> hydro_temp_profile( grid.axis.Nx(0));
192  valarray<double> hydro_vel_profile( grid.axis.Nx(0));
193  valarray<double> hydro_Z_profile( grid.axis.Nx(0));
194 
195 
196 
197  for (size_t s(0); s < Input::List().qs.size(); ++s) {
198 
199  Y.SH(s,0,0) = 0.0;
200 
201  temp_profile = 0.0;
202 
203  parseprofile(grid.axis.x(0), Input::List().dens_profile_str[s], dens_profile);
204  parseprofile(grid.axis.x(0), Input::List().temp_profile_str[s], temp_profile);
205 
206  parseprofile(grid.axis.x(0), Input::List().f10x_profile_str[s], f10x_profile);
207  // parseprofile(grid.axis.x(0), Input::List().f20x_profile_str[s], f20x_profile);
208  parseprofile(grid.axis.x(0), Input::List().f_pedestal[s], pedestal_profile);
209 
210  init_f0(s, Y.SH(s,0,0), grid.axis.p(s), grid.axis.x(0), dens_profile, temp_profile, Y.DF(s).mass(), pedestal_profile);
211 
212  if (Input::List().init_f1) init_f1(s, Y.SH(s,1,0), grid.axis.p(s), grid.axis.x(0), dens_profile, temp_profile, f10x_profile, Y.SH(s,0,0), Y.DF(s).mass());
213 
214  // if (Input::List().init_f2) init_f2(s, Y.SH(s,2,0), grid.axis.p(s), grid.axis.x(0), dens_profile, temp_profile, f20x_profile, Y.DF(s).mass());
215 
216  }
217 
218 // - - - - - - - - - - - - - - - - - - - - - - - - - - - -
219 // - - - - - - - - - - - - - - - - - - - - - - - - - - - -
220 // Setup the electromagnetic fields
221 // - - - - - - - - - - - - - - - - - - - - - - - - - - - -
222 // - - - - - - - - - - - - - - - - - - - - - - - - - - - -
223 
224  Y.EMF() = static_cast<complex<double> >(0.0);
225 
226  parseprofile(grid.axis.x(0), Input::List().hydro_dens_profile_str, hydro_dens_profile);
227  parseprofile(grid.axis.x(0), Input::List().hydro_temp_profile_str, hydro_temp_profile);
228  parseprofile(grid.axis.x(0), Input::List().hydro_vel_profile_str, hydro_vel_profile);
229  parseprofile(grid.axis.x(0), Input::List().hydro_Z_profile_str, hydro_Z_profile);
230 
231 
232  Y.HYDRO().vxarray() = 0.0;
233  Y.HYDRO().vyarray() = 0.0;
234  Y.HYDRO().vzarray() = 0.0;
235  Y.HYDRO().densityarray() = 1.0;
236  Y.HYDRO().temperaturearray() = 1.0;
237  Y.HYDRO().Zarray() = 1.0;
238 
239 
240  for (size_t i(0); i < temp_profile.size(); ++i)
241  {
242 
243  Y.HYDRO().density(i) = hydro_dens_profile[i];
244  Y.HYDRO().temperature(i) = hydro_temp_profile[i];
245  Y.HYDRO().vx(i) = hydro_vel_profile[i];
246  Y.HYDRO().Z(i) = hydro_Z_profile[i];
247 // Y.HYDRO().vy(i) = hydro_vel_profile[i];
248 // Y.HYDRO().vz(i) = hydro_vel_profile[i];
249  // std::cout << "velocity(" << grid.axis.x(0)[i] << ")=" << Y.HYDRO().velocity(i) << "\n";
250  }
251 
252 }
253 //--------------------------------------------------------------
254 //**************************************************************
255 
256 
257 //-----------------------------------------------------------------------------
258 void Setup_Y:: init_f0(size_t s, SHarmonic1D& h, const valarray<double>& p, const valarray<double>& x,
259  valarray<double>& density, valarray<double>& temperature, const double mass, const valarray<double>& pedestal){
260 //-----------------------------------------------------------------------------
261 //-----------------------------------------------------------------------------
262  double alpha, coeff, coefftemp;
263  double m = Input::List().super_gaussian_m;
264 
265  alpha = sqrt(3.0*tgamma(3.0/m)/2.0/tgamma(5.0/m));
266  coeff = m/alpha/alpha/alpha/tgamma(3.0/m);
267  coeff *= sqrt(M_PI)/4.0;
268 
269 // std::cout << "\n alpha = " << alpha << ", coeff = " << coeff << "\n";
270  for (int j(0); j < h.numx(); ++j){
271 
272  coefftemp = coeff*density[j]/pow(2.0*M_PI*temperature[j]*mass,1.5);
273  for (int k(0); k < h.nump(); ++k){
274  // New formulation for temperature distribution and super-Gaussians
275  h(k,j) = coefftemp*exp(-1.0*pow((p[k])/alpha/sqrt(2.0*temperature[j]*mass),m));
276  h(k,j)+= pedestal[j];
277 
278  // h(k,j)= coefftemp*exp(-pow((p[k]-3.0)/alpha/sqrt(2.0*temperature[j]/mass),m));
279  // if (p[k] < 3.0) h(k,j) += 1e-2;
280 // if (j==3) std :: cout << "p = " << p[k] << ", h = " << h(k,j).real() << "\n";
281 
282  }
283 
284  // h(0,j) = 1.425577e2;
285  // h(1,j) = 1.497164e1;
286  // h(2,j) = 1.527841e-1;
287  // h(3,j) = 1.515014e-4;
288  // h(4,j) = 1.459772e-8;
289  // h(5,j) = 1.366732e-13;
290  // h(6,j) = 1.243401e-19;
291  // h(7,j) = 1.099181e-26;
292 
293 
294 
295  }
296 
297 }
298 //----------------------------------------------------------------------------------------------------------------------
299 //----------------------------------------------------------------------------------------------------------------------
300 void Setup_Y:: init_f1(size_t s, SHarmonic1D& h, const valarray<double>& p, const valarray<double>& x,
301  valarray<double>& density, valarray<double>& temperature, valarray<double>& f10x, const SHarmonic1D& f0, const double mass){
302 //----------------------------------------------------------------------------------------------------------------------
303 //----------------------------------------------------------------------------------------------------------------------
304  double alpha, coeff, coefftemp;
305  double m = Input::List().super_gaussian_m;
306 
307  SHarmonic1D df0(f0); df0.Dp();
308 
309  double idp = -0.5/(p[1]-p[0]);
310 
311  alpha = sqrt(3.0*tgamma(3.0/m)/2.0/tgamma(5.0/m));
312  coeff = m/4.0*sqrt(M_PI)*alpha/alpha/alpha/tgamma(3.0/m);
313 
314  for (int j(0); j < h.numx(); ++j){
315 
316  coefftemp = coeff*density[j]/pow(2.0*M_PI*temperature[j]*mass,1.5)*f10x[j];
317  for (int k(0); k < h.nump(); ++k){
318  // New formulation for temperature distribution and super-Gaussians
319 // h(k,j) = coefftemp*exp(-pow((p[k])/alpha/sqrt(2.0*temperature[j]*mass),m))*pow(p[k],3.0)*(p[k]/mass/temperature[j]);
320  h(k,j) = idp*df0(k,j)*pow(p[k],3.0)*f10x[j];
321 
322  // h(k,j)= coefftemp*exp(-pow((p[k]-3.0)/alpha/sqrt(2.0*temperature[j]/mass),m));
323  // if (p[k] < 3.0) h(k,j) += 1e-2;
324 // if (j==3) std :: cout << "p = " << p[k] << ", h = " << h(k,j) << "\n";
325 
326  }
327 
328  }
329 
330 }
331 //----------------------------------------------------------------------------------------------------------------------------
332 //-----------------------------------------------------------------------------
333 void Setup_Y:: init_f2(size_t s, SHarmonic1D& h, const valarray<double>& p, const valarray<double>& x,
334  valarray<double>& density, valarray<double>& temperature, valarray<double>& f20x, const double mass){
335 //-----------------------------------------------------------------------------
336 //-----------------------------------------------------------------------------
337  double alpha, coeff, coefftemp;
338  //Matrix2D<double> coeff(pt);
339  double m = 2.0;
340 
341  alpha = sqrt(3.0*tgamma(3.0/m)/2.0/tgamma(5.0/m));
342  // coeff = m/4.0/M_PI/alpha/alpha/alpha/tgamma(3.0/m);
343  coeff = 1.0;
344 
345  for (int j(0); j < h.numx(); ++j){
346  // std::cout << "temp = " << temperature[j] << "\n";
347  // coefftemp = coeff*density(s,j)/pow(temperature(s,j),1.5);
348  coefftemp = coeff*density[j]/pow(2.0*M_PI*temperature[j]/mass,1.5);
349  for (int k(0); k < h.nump(); ++k){
350  // New formulation for temperature distribution and super-Gaussians
351 
352 
353  // h(k,j)= coefftemp*exp(-pow(p[k]/alpha/sqrt(temperature(s,j)),m));
354  h(k,j)= 2.0*coefftemp*exp(-pow((p[k]-3.0)/alpha/sqrt(2.0*temperature[j]/mass),m));
355  // if (j==3) std :: cout << "p = " << p[k] << ", h = " << h(k,j) << "\n";
356  // h(i,j,k) *= coeff(j,k);
357  // std::cout << h(k,j) << "\n";
358  }
359 
360 
361  // Old formulation for momentum distribution
362  // alpha(j,k) = 1.0/(2.0*pt(j,k)*pt(j,k));
363  // coeff(j,k) = 1.0/(sqrt(2.0*M_PI)*2.0*M_PI*pt(j,k)*pt(j,k)*pt(j,k));
364  // std::cout << "pt=" << pt(j,k) << "\n";
365  }
366 
367 }
368 //----------------------------------------------------------------------------------------------------------------------------
369 //----------------------------------------------------------------------------------------------------------------------------
370 
371 
372 
373 //----------------------------------------------------------------------------------------------------------------------------
374 //----------------------------------------------------------------------------------------------------------------------------
375 void Setup_Y::checkparse(parser_t& parser, std::string& expression_str, expression_t& expression){
376 //----------------------------------------------------------------------------------------------------------------------------
377 //----------------------------------------------------------------------------------------------------------------------------
378 
379 
380  if (!parser.compile(expression_str,expression))
381  {
382  printf("Error: %s\tExpression: %s\n",
383  parser.error().c_str(),
384  expression_str.c_str());
385 
386  for (std::size_t i = 0; i < parser.error_count(); ++i)
387  {
388  error_t error = parser.get_error(i);
389  printf("Error: %02d Position: %02d Type: [%s] Msg: %s Expr: %s\n",
390  static_cast<int>(i),
391  static_cast<int>(error.token.position),
392  exprtk::parser_error::to_str(error.mode).c_str(),
393  error.diagnostic.c_str(),
394  expression_str.c_str());
395  }
396 
397  exit(1);
398  }
399 
400 
401 }
402 //----------------------------------------------------------------------------------------------------------------------------
409 //----------------------------------------------------------------------------------------------------------------------------
410 void Setup_Y::parseprofile( const valarray<double>& grid, std::string& str_profile, valarray<double>& profile){
411 
413  std::size_t posL = str_profile.find("{");
414  std::size_t posR = str_profile.find("}");
415 
417  if (str_profile[0] == 'c')
418  {
419  // std::cout<< "expression_str is " << str_profile.substr(posL+1,posR-(posL+1)) << "\n";
420  profile = std::stod(str_profile.substr(posL+1,posR-(posL+1)));
421  }
422 
424  if (str_profile[0] == 'f')
425  {
427  std::string expression_str = str_profile.substr(posL+1,posR-(posL+1));
428 
429  symbol_table_t symbol_table;
430  symbol_table.add_constants();
431  double xstr;
432  symbol_table.add_variable("x",xstr);
433 
434  expression_t expression;
435 
436  expression.register_symbol_table(symbol_table);
437 
438  parser_t parser;
439 
440  checkparse(parser, expression_str, expression);
441 
442  for (size_t i(0); i < profile.size(); ++i) {
443  xstr = grid[i];
444  // std::cout<< "i= " << i << ",xstr = " << xstr << "\n";
445 
446  // result =
447  // Temperature_map(s,i) = expression_Temperature.value();
448  profile[i] = expression.value();
449  // std::cout << i << " , " << grid[i] << " , " << profile[i] << "\n";
450  // printf("Result: %10.5f\n",expression.value());
451  }
452  }
453 
454  if (str_profile[0] == 'p'){
455  std::string pcw_pairs = str_profile.substr(posL+1,posR-(posL+1));
456  vector<size_t> positions_comma, positions_semicolon; // holds all the positions that sub occurs within str
457  vector<double> loc,val;
458  size_t pos = pcw_pairs.find(',', 0);
459  while(pos != string::npos)
460  {
461  positions_comma.push_back(pos);
462  pos = pcw_pairs.find(',',pos+1);
463  }
464 
465  pos = pcw_pairs.find(';', 0);
466  while(pos != string::npos)
467  {
468  positions_semicolon.push_back(pos);
469  pos = pcw_pairs.find(';',pos+1);
470  }
471 
472  if (positions_comma.size() != positions_semicolon.size()){
473  std::cout << "Error in piecewise input, the values must be supplied in pairs with ',' in between the two values in each pair, and ending each pair with a ';'. E.g. {0.1,1.0;0.2,1.5;} \n";
474 
475  exit(1);
476  }
477 
478 
479  loc.push_back(std::stod(pcw_pairs.substr(0,positions_comma[0]-1)));
480  val.push_back(std::stod(pcw_pairs.substr(positions_comma[0]+1,positions_semicolon[0]-positions_comma[0]-1)));
481 
482  // std::cout << "loc0 = " << loc[0] << endl;
483  // std::cout << "val0 = " << val[0] << endl;
484 
485  for (size_t i(1); i < positions_comma.size(); ++i) {
486 
487  loc.push_back(std::stod(pcw_pairs.substr(positions_semicolon[i-1]+1,positions_comma[i]-positions_semicolon[i-1]-1)));
488  val.push_back(std::stod(pcw_pairs.substr(positions_comma[i]+1,positions_semicolon[i]-positions_comma[i]-1)));
489 
490  // std::cout << "loci = " << loc[i] << endl;
491  // std::cout << "vali = " << val[i] << endl;
492 
493  }
494 
495 
496  double tmp_x, xx;
497  size_t t(0);
498  for (size_t i(0); i < grid.size(); ++i) {
499  t = 1;
500  xx = grid[i];
501  if (grid[i] < loc[0]) xx += loc[loc.size()-1] - loc[0];
502  if (grid[i] > loc[loc.size()-1]) xx += loc[0]-loc[loc.size()-1] ;
503 
504  while ((xx > loc[t]) && (t < loc.size()-1)) ++t;
505  tmp_x = val[t-1] + (val[t]-val[t-1])/(loc[t]-loc[t-1])
506  * (xx - loc[t-1]);
507  // std::cout << i << " " << x[i] << " " << tmp_x << std::endl;
508  // for (size_t j(0); j < Temp.dim2(); ++j) Temp(i,j) *= tmp_x;
509  profile[i] = tmp_x;
510  }
511  }
512 }
513 //----------------------------------------------------------------------------------------------------------------------------
520 //----------------------------------------------------------------------------------------------------------------------------
521 void Setup_Y::parseprofile(const double& input, std::string& str_profile, double& output){
522 
524  std::size_t posL = str_profile.find("{");
525  std::size_t posR = str_profile.find("}");
526 
528  if (str_profile[0] == 'c')
529  {
530  // std::cout<< "expression_str is " << str_profile.substr(posL+1,posR-(posL+1)) << "\n";
531  output = std::stod(str_profile.substr(posL+1,posR-(posL+1)));
532  }
533 
535  if (str_profile[0] == 'f')
536  {
538  std::string expression_str = str_profile.substr(posL+1,posR-(posL+1));
539 
540  symbol_table_t symbol_table;
541  symbol_table.add_constants();
542  double xstr;
543  symbol_table.add_variable("t",xstr);
544 
545  expression_t expression;
546 
547  expression.register_symbol_table(symbol_table);
548 
549  parser_t parser;
550 
551  checkparse(parser, expression_str, expression);
552 
553  // for (size_t i(0); i < profile.size(); ++i) {
554  xstr = input;
555  // std::cout<< "i= " << i << ",xstr = " << xstr << "\n";
556 
557  // result =
558  // Temperature_map(s,i) = expression_Temperature.value();
559  output = expression.value();
560  // std::cout << " \n 10: " << input << " , " << output << "\n";
561  // exit(1);
562  // printf("Result: %10.5f\n",expression.value());
563 
564  }
565 
566  // if (str_profile[0] == 'p'){
567  // std::string pcw_pairs = str_profile.substr(posL+1,posR-(posL+1));
568  // vector<size_t> positions_comma, positions_semicolon; // holds all the positions that sub occurs within str
569  // vector<double> loc,val;
570  // size_t pos = pcw_pairs.find(',', 0);
571  // while(pos != string::npos)
572  // {
573  // positions_comma.push_back(pos);
574  // pos = pcw_pairs.find(',',pos+1);
575  // }
576 
577  // pos = pcw_pairs.find(';', 0);
578  // while(pos != string::npos)
579  // {
580  // positions_semicolon.push_back(pos);
581  // pos = pcw_pairs.find(';',pos+1);
582  // }
583 
584  // if (positions_comma.size() != positions_semicolon.size()){
585  // std::cout << "Error in piecewise input, the values must be supplied in pairs with ',' in between the two values in each pair, and ending each pair with a ';'. E.g. {0.1,1.0;0.2,1.5;} \n";
586 
587  // exit(1);
588  // }
589 
590 
591  // loc.push_back(std::stod(pcw_pairs.substr(0,positions_comma[0]-1)));
592  // val.push_back(std::stod(pcw_pairs.substr(positions_comma[0]+1,positions_semicolon[0]-positions_comma[0]-1)));
593 
594  // // std::cout << "loc0 = " << loc[0] << endl;
595  // // std::cout << "val0 = " << val[0] << endl;
596 
597  // for (size_t i(1); i < positions_comma.size(); ++i) {
598 
599  // loc.push_back(std::stod(pcw_pairs.substr(positions_semicolon[i-1]+1,positions_comma[i]-positions_semicolon[i-1]-1)));
600  // val.push_back(std::stod(pcw_pairs.substr(positions_comma[i]+1,positions_semicolon[i]-positions_comma[i]-1)));
601 
602  // // std::cout << "loci = " << loc[i] << endl;
603  // // std::cout << "vali = " << val[i] << endl;
604 
605  // }
606 
607 
608  // double tmp_x, xx;
609  // size_t t(0);
610  // for (size_t i(0); i < grid.size(); ++i) {
611  // t = 1;
612  // xx = grid[i];
613  // if (grid[i] < loc[0]) xx += loc[loc.size()-1] - loc[0];
614  // if (grid[i] > loc[loc.size()-1]) xx += loc[0]-loc[loc.size()-1] ;
615 
616  // while ((xx > loc[t]) && (t < loc.size()-1)) ++t;
617  // tmp_x = val[t-1] + (val[t]-val[t-1])/(loc[t]-loc[t-1])
618  // * (xx - loc[t-1]);
619  // // std::cout << i << " " << x[i] << " " << tmp_x << std::endl;
620  // // for (size_t j(0); j < Temp.dim2(); ++j) Temp(i,j) *= tmp_x;
621  // profile[i] = tmp_x;
622  // }
623  // }
624 }
625 //----------------------------------------------------------------------------------------------------------------------------
632 //----------------------------------------------------------------------------------------------------------------------------
633 void Setup_Y::parsetwovariableprofile(const valarray<double>& grid, const double& input, std::string& str_profile, valarray<double>& output){
634 
636  std::size_t posL = str_profile.find("{");
637  std::size_t posR = str_profile.find("}");
638 
640  if (str_profile[0] == 'c')
641  {
642  // std::cout<< "expression_str is " << str_profile.substr(posL+1,posR-(posL+1)) << "\n";
643  output = std::stod(str_profile.substr(posL+1,posR-(posL+1)));
644  }
645 
647  if (str_profile[0] == 'f')
648  {
650  std::string expression_str = str_profile.substr(posL+1,posR-(posL+1));
651 
652  symbol_table_t symbol_table;
653  symbol_table.add_constants();
654  double xstr, tstr;
655  symbol_table.add_variable("x",xstr);
656  symbol_table.add_variable("t",tstr);
657 
658  expression_t expression;
659 
660  expression.register_symbol_table(symbol_table);
661 
662  parser_t parser;
663 
664  checkparse(parser, expression_str, expression);
665  tstr = input;
666 
667  for (size_t i(0); i < output.size(); ++i) {
668  xstr = grid[i];
669 
670  output[i] = expression.value();
671  }
672 
673 
674 
675  }
676 
677 }
678 
679 //----------------------------------------------------------------------------------------------------------------------------
680 //----------------------------------------------------------------------------------------------------------------------------
681 //><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><
Algorithms
valarray< double > & temperaturearray() const
Definition: state.h:549
Plasma Formulary and Units - Declarations.
std::vector< std::string > ez_wave_profile_str
Definition: input.h:140
Field1D & By()
Definition: state.h:294
std::vector< std::string > bz_wave_profile_str
Definition: input.h:143
Input reader - Declarations.
void init_f0(size_t s, SHarmonic1D &h, const valarray< double > &p, const valarray< double > &x, valarray< double > &density, valarray< double > &temperature, const double mass, const valarray< double > &pedestal)
Definition: setup.cpp:258
std::vector< double > trav_wave_center
Definition: input.h:148
std::string hydro_dens_profile_str
Definition: input.h:108
exprtk::parser< double > parser_t
Definition: setup.h:57
Underlying data structures.
std::string bz_profile_str
Definition: input.h:136
std::string by_profile_str
Definition: input.h:135
void applyexternalfields(Grid_Info &grid, State1D &Y, double time)
Definition: setup.cpp:51
std::string ex_profile_str
Definition: input.h:131
exprtk::expression< double > expression_t
Definition: setup.h:56
std::vector< std::string > ex_wave_profile_str
Definition: input.h:138
std::vector< double > trav_wave_rise
Definition: input.h:145
std::vector< double > qs
Definition: input.h:154
exprtk::symbol_table< double > symbol_table_t
Definition: setup.h:55
void parsetwovariableprofile(const valarray< double > &grid, const double &input, std::string &str_profile, valarray< double > &ouput)
{ function_description }
Definition: setup.cpp:633
double mass() const
Definition: state.h:400
std::vector< std::string > temp_profile_str
Definition: input.h:103
exprtk::parser_error::type error_t
Definition: setup.h:58
void initialize(State1D &Y, Grid_Info &grid)
Definition: setup.cpp:177
std::string hydro_temp_profile_str
Definition: input.h:109
std::vector< std::string > f_pedestal
Definition: input.h:106
std::string ey_profile_str
Definition: input.h:132
size_t numx() const
Definition: state.h:72
Field1D & Ez()
Definition: state.h:292
std::vector< double > trav_wave_flat
Definition: input.h:146
std::vector< double > trav_wave_fall
Definition: input.h:147
A 1D Spherical Harmonic.
Definition: state.h:57
std::vector< std::string > by_wave_profile_str
Definition: input.h:142
void init_f1(size_t s, SHarmonic1D &h, const valarray< double > &p, const valarray< double > &x, valarray< double > &density, valarray< double > &temperature, valarray< double > &f10x, const SHarmonic1D &f0, const double mass)
Definition: setup.cpp:300
SHarmonic1D & Dp()
Definition: state.cpp:139
valarray< double > & vyarray() const
Definition: state.h:547
Definition: state.h:577
std::string hydro_vel_profile_str
Definition: input.h:110
Field1D & Bx()
Definition: state.h:293
valarray< double > & Zarray() const
Definition: state.h:550
Hydro1D & HYDRO()
Definition: state.h:613
double & temperature(size_t i)
Definition: state.h:539
double & Z(size_t i)
Definition: state.h:542
double super_gaussian_m
Definition: input.h:91
size_t nump() const
Definition: state.h:71
std::string ez_profile_str
Definition: input.h:133
Field1D & Bz()
Definition: state.h:295
DistFunc1D & DF(size_t s)
Definition: state.h:602
SHarmonic1D & SH(size_t s, size_t lh, size_t mh)
Definition: state.h:605
Grid Setup - Declaration.
std::vector< std::string > f10x_profile_str
Definition: input.h:104
Fields, Distributions, Harmonics, States - Declarations.
Field1D & Ex()
Definition: state.h:290
valarray< double > & densityarray() const
Definition: state.h:545
valarray< double > & vzarray() const
Definition: state.h:548
void init_f2(size_t s, SHarmonic1D &h, const valarray< double > &p, const valarray< double > &x, valarray< double > &density, valarray< double > &temperature, valarray< double > &f20x, const double mass)
Definition: setup.cpp:333
double & vx(size_t i)
Definition: state.h:530
valarray< T > p(size_t i) const
const Algorithms::AxisBundle< double > axis
Definition: setup.h:47
std::vector< std::string > bx_wave_profile_str
Definition: input.h:141
std::string hydro_Z_profile_str
Definition: input.h:111
void applytravelingwave(Grid_Info &grid, State1D &Y, double time)
Definition: setup.cpp:95
Input_List & List()
Definition: input.cpp:1585
std::string bx_profile_str
Definition: input.h:134
bool init_f1
Definition: input.h:87
double & density(size_t i)
Definition: state.h:527
Field1D & Ey()
Definition: state.h:291
std::vector< std::string > ey_wave_profile_str
Definition: input.h:139
std::vector< std::string > dens_profile_str
Initialization.
Definition: input.h:102
size_t Nx(size_t i) const
valarray< double > & vxarray() const
Definition: state.h:546
void parseprofile(const valarray< double > &grid, std::string &str_profile, valarray< double > &profile)
{ function_description }
Definition: setup.cpp:410
valarray< T > x(size_t i) const
void checkparse(parser_t &parser, std::string &expression_str, expression_t &expression)
Definition: setup.cpp:375
EMF1D & EMF() const
Definition: state.h:610