8 return f0*(1.0 -
x) + f1*x;
14 "In ConstantStepOdeSolver::getPeakTime: index out of range");
16 "In ConstantStepOdeSolver::getPeakTime: not enough data");
19 double maxval = hbuf[0];
22 if (hbuf[
dim_*
i] > maxval)
24 maxval = hbuf[
dim_*
i];
29 if (maxind == runLen_-1U)
31 const double l = hbuf[
dim_*(maxind - 1U)];
32 const double r = hbuf[
dim_*(maxind + 1U)];
33 if (l < maxval || r < maxval)
34 return dt_*(maxind + (l -
r)/2.0/(l + r - 2.0*maxval));
40 const unsigned which,
const unsigned idx)
const
43 "In ConstantStepOdeSolver::getIntegrated: index out of range");
52 "In ConstantStepOdeSolver::integrateCoordinate: not enough data");
59 integ[1] = coord[
dim_*0]*(3.0/8.0) +
60 coord[
dim_*1]*(19.0/24.0) +
61 coord[
dim_*2]*(-5.0/24.0) +
62 coord[
dim_*3]*(1.0/24.0);
63 long double sum = integ[1];
64 const unsigned rlenm1 =
runLen_ - 1U;
65 for (
unsigned i=2;
i<rlenm1; ++
i)
67 sum += (coord[
dim_*(
i-2U)]*(-1.0/24.0) +
68 coord[
dim_*(
i-1U)]*(13.0/24.0) +
69 coord[
dim_*
i] *(13.0/24.0) +
70 coord[
dim_*(
i+1U)]*(-1.0/24.0));
73 sum += (coord[
dim_*rlenm1] *(3.0/8.0) +
74 coord[
dim_*(rlenm1-1U)]*(19.0/24.0) +
75 coord[
dim_*(rlenm1-2U)]*(-5.0/24.0) +
76 coord[
dim_*(rlenm1-3U)]*(1.0/24.0));
86 const bool cubic)
const
93 for (
unsigned ipt=0; ipt<
runLen_; ++ipt)
96 for (
unsigned which=0; which<
dim_; ++which)
104 for (
unsigned i=0; ; ++
i)
106 const double t =
i*
dt;
110 for (
unsigned which=0; which<
dim_; ++which)
119 const unsigned which,
121 const bool cubic)
const
128 for (
unsigned ipt=0; ipt<
runLen_; ++ipt)
134 for (
unsigned i=0; ; ++
i)
136 const double t =
i*
dt;
150 lastIntegrated_(r.lastIntegrated_),
151 historyBuffer_(r.historyBuffer_),
152 chargeBuffer_(r.chargeBuffer_)
177 const double minValue,
178 const double maxValue)
181 "In ConstantStepOdeSolver::truncateCoordinate: index out of range");
183 "In ConstantStepOdeSolver::truncateCoordinate: invalid truncation range");
188 if (buf[
dim_*
i] < minValue)
189 buf[
dim_*
i] = minValue;
190 else if (buf[
dim_*
i] > maxValue)
191 buf[
dim_*
i] = maxValue;
196 const unsigned which,
const double t,
const bool cubic)
const
199 "In ConstantStepOdeSolver::interpolateCoordinate: index out of range");
201 "In ConstantStepOdeSolver::interpolateCoordinate: not enough data");
204 "In ConstantStepOdeSolver::interpolateCoordinate: time out of range");
213 const double tSteps = t/
dt_;
214 unsigned nLow = tSteps;
217 double x = tSteps - nLow;
232 const double*
base = arr + (which +
dim_*i0);
242 const unsigned which,
const double t,
const bool cubic)
const
245 "In ConstantStepOdeSolver::interpolateIntegrated: index out of range");
247 "In ConstantStepOdeSolver::interpolateIntegrated: not enough data");
250 "In ConstantStepOdeSolver::interpolateIntegrated: time out of range");
261 const double tSteps = t/
dt_;
262 unsigned nLow = tSteps;
265 double x = tSteps - nLow;
280 const double*
base = buf + i0;
290 const unsigned dim,
const unsigned runLen)
292 const unsigned len = dim*runLen;
296 "In ConstantStepOdeSolver::setHistory: can not run backwards in time");
298 const unsigned sz = dim*(runLen + 1U);
306 for (
unsigned i=0;
i<len; ++
i)
308 for (
unsigned i=0;
i<dim; ++
i)
313 const unsigned lenInitialConditions,
314 const double dt,
const unsigned nSteps)
316 if (!nSteps || !lenInitialConditions)
319 "In ConstantStepOdeSolver::run: ODE right hand side has not been set");
321 "In ConstantStepOdeSolver::run: can not run backwards in time");
322 assert(initialConditions);
324 dim_ = lenInitialConditions;
331 for (
unsigned i=0;
i<lenInitialConditions; ++
i)
332 arr[
i] = initialConditions[
i];
335 for (
unsigned i = 0;
i < nSteps; ++
i, arr += lenInitialConditions)
337 const double t =
i*
dt;
338 this->
step(t, dt, arr, lenInitialConditions, stepBuffer);
339 double*
next = arr + lenInitialConditions;
340 for (
unsigned i=0;
i<lenInitialConditions; ++
i)
341 next[
i] = arr[
i] + stepBuffer[
i];
346 const double*
x,
const unsigned lenX,
347 double* coordIncrement)
const
349 rhs_->
calc(t, x, lenX, coordIncrement);
350 for (
unsigned i=0;
i<lenX; ++
i)
351 coordIncrement[
i] *= dt;
355 const double*
x,
const unsigned lenX,
356 double* coordIncrement)
const
358 const double halfstep = dt/2.0;
359 if (
buf_.size() < lenX)
361 double* midpoint = &
buf_[0];
363 for (
unsigned i=0;
i<lenX; ++
i)
365 midpoint[
i] *= halfstep;
368 rhs_->
calc(t + halfstep, midpoint, lenX, coordIncrement);
369 for (
unsigned i=0;
i<lenX; ++
i)
370 coordIncrement[
i] *= dt;
374 const double*
x,
const unsigned lenX,
375 double* coordIncrement)
const
377 const double halfstep = dt/2.0;
378 if (
buf_.size() < 4*lenX)
380 double* k1x = &
buf_[0];
381 double* k2x = k1x + lenX;
382 double* k3x = k2x + lenX;
383 double* k4x = k3x + lenX;
385 for (
unsigned i=0;
i<lenX; ++
i)
386 coordIncrement[
i] = x[
i] + halfstep*k1x[
i];
387 rhs_->
calc(t + halfstep, coordIncrement, lenX, k2x);
388 for (
unsigned i=0;
i<lenX; ++
i)
389 coordIncrement[
i] = x[
i] + halfstep*k2x[
i];
390 rhs_->
calc(t + halfstep, coordIncrement, lenX, k3x);
391 for (
unsigned i=0;
i<lenX; ++
i)
392 coordIncrement[
i] = x[
i] + dt*k3x[
i];
393 rhs_->
calc(t + dt, coordIncrement, lenX, k4x);
394 for (
unsigned i=0;
i<lenX; ++
i)
395 coordIncrement[
i] = dt/6.0*(k1x[
i] + 2.0*(k2x[
i] + k3x[
i]) + k4x[i]);
static double interpolateLinear(const double x, const double f0, const double f1)
virtual AbsODERHS * clone() const =0
double getCoordinate(const unsigned which, const unsigned idx) const
double interpolateIntegrated(unsigned which, double t, bool cubic=false) const
double getTime(const unsigned idx) const
std::vector< double > chargeBuffer_
double getPeakTime(unsigned which) const
void step(double t, double dt, const double *x, unsigned lenX, double *coordIncrement) const
T x() const
Cartesian x coordinate.
double getIntegrated(unsigned which, unsigned idx) const
void writeIntegrated(std::ostream &os, unsigned which, double dt, bool cubic=false) const
virtual void step(double t, double dt, const double *x, unsigned lenX, double *coordIncrement) const =0
std::vector< double > buf_
virtual const char * methodName() const =0
void integrateCoordinate(const unsigned which)
virtual void calc(double t, const double *x, unsigned lenX, double *derivative)=0
static const double tmax[3]
ConstantStepOdeSolver & operator=(const ConstantStepOdeSolver &r)
double interpolateCoordinate(unsigned which, double t, bool cubic=false) const
std::vector< double > historyBuffer_
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
void step(double t, double dt, const double *x, unsigned lenX, double *coordIncrement) const
void step(double t, double dt, const double *x, unsigned lenX, double *coordIncrement) const
void run(const double *initialConditions, unsigned lenConditions, double dt, unsigned nSteps)
std::vector< double > buf_
void truncateCoordinate(unsigned which, double minValue, double maxValue)
void writeHistory(std::ostream &os, double dt, bool cubic=false) const
void setHistory(double dt, const double *data, unsigned dim, unsigned runLen)