CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
ConstantStepOdeSolver Class Referenceabstract

#include <ConstantStepOdeSolver.h>

Inheritance diagram for ConstantStepOdeSolver:
EulerOdeSolver RK2 RK4

Public Member Functions

 ConstantStepOdeSolver ()
 
 ConstantStepOdeSolver (const AbsODERHS &rhs)
 
 ConstantStepOdeSolver (const ConstantStepOdeSolver &r)
 
double getCoordinate (const unsigned which, const unsigned idx) const
 
double getIntegrated (unsigned which, unsigned idx) const
 
double getPeakTime (unsigned which) const
 
const AbsODERHSgetRHS () const
 
AbsODERHSgetRHS ()
 
double getTime (const unsigned idx) const
 
double interpolateCoordinate (unsigned which, double t, bool cubic=false) const
 
double interpolateIntegrated (unsigned which, double t, bool cubic=false) const
 
double lastDeltaT () const
 
unsigned lastDim () const
 
double lastMaxT () const
 
unsigned lastRunLength () const
 
virtual const char * methodName () const =0
 
ConstantStepOdeSolveroperator= (const ConstantStepOdeSolver &r)
 
void run (const double *initialConditions, unsigned lenConditions, double dt, unsigned nSteps)
 
void setHistory (double dt, const double *data, unsigned dim, unsigned runLen)
 
void setRHS (const AbsODERHS &rhs)
 
void truncateCoordinate (unsigned which, double minValue, double maxValue)
 
void writeHistory (std::ostream &os, double dt, bool cubic=false) const
 
void writeIntegrated (std::ostream &os, unsigned which, double dt, bool cubic=false) const
 
virtual ~ConstantStepOdeSolver ()
 

Protected Attributes

AbsODERHSrhs_
 

Private Member Functions

void integrateCoordinate (const unsigned which)
 
virtual void step (double t, double dt, const double *x, unsigned lenX, double *coordIncrement) const =0
 

Private Attributes

std::vector< double > chargeBuffer_
 
unsigned dim_
 
double dt_
 
std::vector< double > historyBuffer_
 
unsigned lastIntegrated_
 
unsigned runLen_
 

Detailed Description

Definition at line 14 of file ConstantStepOdeSolver.h.

Constructor & Destructor Documentation

ConstantStepOdeSolver::ConstantStepOdeSolver ( )
inline
ConstantStepOdeSolver::ConstantStepOdeSolver ( const AbsODERHS rhs)
inline

Definition at line 20 of file ConstantStepOdeSolver.h.

References AbsODERHS::clone(), and rhs_.

20  :
21  rhs_(0), dt_(0.0), dim_(0), runLen_(0), lastIntegrated_(0)
22  {
23  rhs_ = rhs.clone();
24  }
virtual AbsODERHS * clone() const =0
ConstantStepOdeSolver::ConstantStepOdeSolver ( const ConstantStepOdeSolver r)

Definition at line 145 of file ConstantStepOdeSolver.cc.

References AbsODERHS::clone(), and rhs_.

146  : rhs_(0),
147  dt_(r.dt_),
148  dim_(r.dim_),
149  runLen_(r.runLen_),
153 {
154  if (r.rhs_)
155  rhs_ = r.rhs_->clone();
156 }
virtual AbsODERHS * clone() const =0
std::vector< double > chargeBuffer_
std::vector< double > historyBuffer_
virtual ConstantStepOdeSolver::~ConstantStepOdeSolver ( )
inlinevirtual

Definition at line 30 of file ConstantStepOdeSolver.h.

References rhs_.

30 {delete rhs_;}

Member Function Documentation

double ConstantStepOdeSolver::getCoordinate ( const unsigned  which,
const unsigned  idx 
) const
inline

Definition at line 54 of file ConstantStepOdeSolver.h.

References dim_, edm::hlt::Exception, historyBuffer_, and runLen_.

Referenced by writeHistory().

55  {
56  if (which >= dim_ || idx >= runLen_) throw cms::Exception(
57  "In ConstantStepOdeSolver::getCoordinate: index out of range");
58  return historyBuffer_[dim_*idx + which];
59  }
std::vector< double > historyBuffer_
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
double ConstantStepOdeSolver::getIntegrated ( unsigned  which,
unsigned  idx 
) const

Definition at line 39 of file ConstantStepOdeSolver.cc.

References chargeBuffer_, dim_, edm::hlt::Exception, customizeTrackingMonitorSeedNumber::idx, lastIntegrated_, and runLen_.

Referenced by writeIntegrated().

41 {
42  if (which >= dim_ || idx >= runLen_) throw cms::Exception(
43  "In ConstantStepOdeSolver::getIntegrated: index out of range");
44  if (lastIntegrated_ != which)
45  (const_cast<ConstantStepOdeSolver*>(this))->integrateCoordinate(which);
46  return chargeBuffer_[idx];
47 }
std::vector< double > chargeBuffer_
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
double ConstantStepOdeSolver::getPeakTime ( unsigned  which) const

Definition at line 11 of file ConstantStepOdeSolver.cc.

References dim_, dt_, edm::hlt::Exception, historyBuffer_, i, prof2calltree::l, alignCSCRings::r, and runLen_.

Referenced by QIE8Simulator::preampPeakTime().

12 {
13  if (which >= dim_) throw cms::Exception(
14  "In ConstantStepOdeSolver::getPeakTime: index out of range");
15  if (runLen_ < 3) throw cms::Exception(
16  "In ConstantStepOdeSolver::getPeakTime: not enough data");
17 
18  const double* hbuf = &historyBuffer_[which];
19  double maxval = hbuf[0];
20  unsigned maxind = 0;
21  for (unsigned i=1; i<runLen_; ++i)
22  if (hbuf[dim_*i] > maxval)
23  {
24  maxval = hbuf[dim_*i];
25  maxind = i;
26  }
27  if (maxind == 0U)
28  return 0.0;
29  if (maxind == runLen_-1U)
30  return dt_*maxind;
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));
35  else
36  return dt_*maxind;
37 }
int i
Definition: DBlmapReader.cc:9
std::vector< double > historyBuffer_
const AbsODERHS* ConstantStepOdeSolver::getRHS ( ) const
inline

Definition at line 38 of file ConstantStepOdeSolver.h.

References rhs_.

Referenced by QIE8Simulator::getRHS(), and QIE8Simulator::modifiableRHS().

38 {return rhs_;}
AbsODERHS* ConstantStepOdeSolver::getRHS ( )
inline

Definition at line 39 of file ConstantStepOdeSolver.h.

References rhs_.

39 {return rhs_;}
double ConstantStepOdeSolver::getTime ( const unsigned  idx) const
inline

Definition at line 47 of file ConstantStepOdeSolver.h.

References dt_, edm::hlt::Exception, and runLen_.

Referenced by writeHistory(), and writeIntegrated().

48  {
49  if (idx >= runLen_) throw cms::Exception(
50  "In ConstantStepOdeSolver::getTime: index out of range");
51  return idx*dt_;
52  }
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
void ConstantStepOdeSolver::integrateCoordinate ( const unsigned  which)
private

Definition at line 49 of file ConstantStepOdeSolver.cc.

References chargeBuffer_, dim_, dt_, edm::hlt::Exception, historyBuffer_, i, lastIntegrated_, and runLen_.

50 {
51  if (runLen_ < 4) throw cms::Exception(
52  "In ConstantStepOdeSolver::integrateCoordinate: not enough data");
53  if (chargeBuffer_.size() < runLen_)
54  chargeBuffer_.resize(runLen_);
55  double* integ = &chargeBuffer_[0];
56  const double* coord = &historyBuffer_[which];
57 
58  integ[0] = 0.0;
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)
66  {
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));
71  integ[i] = sum;
72  }
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));
77  integ[rlenm1] = sum;
78  if (dt_ != 1.0)
79  for (unsigned i=1; i<runLen_; ++i)
80  integ[i] *= dt_;
81  lastIntegrated_ = which;
82 }
int i
Definition: DBlmapReader.cc:9
std::vector< double > chargeBuffer_
std::vector< double > historyBuffer_
double ConstantStepOdeSolver::interpolateCoordinate ( unsigned  which,
double  t,
bool  cubic = false 
) const

Definition at line 195 of file ConstantStepOdeSolver.cc.

References newFWLiteAna::base, dim_, dt_, edm::hlt::Exception, historyBuffer_, interpolateLinear(), runLen_, and x.

Referenced by QIE8Simulator::controlOutput(), QIE8Simulator::getCharge(), QIE8Simulator::preampOutput(), and writeHistory().

197 {
198  if (which >= dim_) throw cms::Exception(
199  "In ConstantStepOdeSolver::interpolateCoordinate: index out of range");
200  if (runLen_ < 2U || (cubic && runLen_ < 4U)) throw cms::Exception(
201  "In ConstantStepOdeSolver::interpolateCoordinate: not enough data");
202  const double maxt = runLen_ ? dt_*(runLen_-1U) : 0.0;
203  if (t < 0.0 || t > maxt) throw cms::Exception(
204  "In ConstantStepOdeSolver::interpolateCoordinate: time out of range");
205 
206  const double* arr = &historyBuffer_[0];
207  if (t == 0.0)
208  return arr[which];
209  else if (t == maxt)
210  return arr[which + dim_*(runLen_-1U)];
211 
212  // Translate time into timestep units
213  const double tSteps = t/dt_;
214  unsigned nLow = tSteps;
215  if (nLow >= runLen_ - 1)
216  nLow = runLen_ - 2;
217  double x = tSteps - nLow;
218 
219  if (cubic)
220  {
221  unsigned i0 = 0;
222  if (nLow == runLen_ - 2)
223  {
224  i0 = nLow - 2U;
225  x += 2.0;
226  }
227  else if (nLow)
228  {
229  i0 = nLow - 1U;
230  x += 1.0;
231  }
232  const double* base = arr + (which + dim_*i0);
233  return interpolateLinear(x*(3.0 - x)/2.0,
234  interpolateLinear(x/3.0, base[0], base[dim_*3]),
235  interpolateLinear(x-1.0, base[dim_], base[dim_*2]));
236  }
237  else
238  return interpolateLinear(x, arr[which+dim_*nLow], arr[which+dim_*(nLow+1U)]);
239 }
static double interpolateLinear(const double x, const double f0, const double f1)
tuple base
Main Program
Definition: newFWLiteAna.py:92
tuple t
Definition: tree.py:139
std::vector< double > historyBuffer_
double ConstantStepOdeSolver::interpolateIntegrated ( unsigned  which,
double  t,
bool  cubic = false 
) const

Definition at line 241 of file ConstantStepOdeSolver.cc.

References newFWLiteAna::base, chargeBuffer_, dim_, dt_, edm::hlt::Exception, interpolateLinear(), lastIntegrated_, runLen_, and x.

Referenced by QIE8Simulator::getCharge(), and writeIntegrated().

243 {
244  if (which >= dim_) throw cms::Exception(
245  "In ConstantStepOdeSolver::interpolateIntegrated: index out of range");
246  if (runLen_ < 2U || (cubic && runLen_ < 4U)) throw cms::Exception(
247  "In ConstantStepOdeSolver::interpolateIntegrated: not enough data");
248  const double maxt = runLen_ ? dt_*(runLen_-1U) : 0.0;
249  if (t < 0.0 || t > maxt) throw cms::Exception(
250  "In ConstantStepOdeSolver::interpolateIntegrated: time out of range");
251  if (lastIntegrated_ != which)
252  (const_cast<ConstantStepOdeSolver*>(this))->integrateCoordinate(which);
253 
254  const double* buf = &chargeBuffer_[0];
255  if (t == 0.0)
256  return buf[0];
257  else if (t == maxt)
258  return buf[runLen_-1U];
259 
260  // Translate time into timestep units
261  const double tSteps = t/dt_;
262  unsigned nLow = tSteps;
263  if (nLow >= runLen_ - 1)
264  nLow = runLen_ - 2;
265  double x = tSteps - nLow;
266 
267  if (cubic)
268  {
269  unsigned i0 = 0;
270  if (nLow == runLen_ - 2)
271  {
272  i0 = nLow - 2U;
273  x += 2.0;
274  }
275  else if (nLow)
276  {
277  i0 = nLow - 1U;
278  x += 1.0;
279  }
280  const double* base = buf + i0;
281  return interpolateLinear(x*(3.0 - x)/2.0,
282  interpolateLinear(x/3.0, base[0], base[3]),
283  interpolateLinear(x-1.0, base[1], base[2]));
284  }
285  else
286  return interpolateLinear(x, buf[nLow], buf[nLow+1U]);
287 }
static double interpolateLinear(const double x, const double f0, const double f1)
tuple base
Main Program
Definition: newFWLiteAna.py:92
tuple t
Definition: tree.py:139
std::vector< double > chargeBuffer_
double ConstantStepOdeSolver::lastDeltaT ( ) const
inline

Definition at line 44 of file ConstantStepOdeSolver.h.

References dt_.

Referenced by operator<<().

44 {return dt_;}
unsigned ConstantStepOdeSolver::lastDim ( ) const
inline

Definition at line 42 of file ConstantStepOdeSolver.h.

References dim_.

42 {return dim_;}
double ConstantStepOdeSolver::lastMaxT ( ) const
inline
unsigned ConstantStepOdeSolver::lastRunLength ( ) const
inline

Definition at line 43 of file ConstantStepOdeSolver.h.

References runLen_.

43 {return runLen_;}
virtual const char* ConstantStepOdeSolver::methodName ( ) const
pure virtual

Implemented in RK4, RK2, and EulerOdeSolver.

Referenced by writeHistory(), and writeIntegrated().

ConstantStepOdeSolver & ConstantStepOdeSolver::operator= ( const ConstantStepOdeSolver r)

Definition at line 158 of file ConstantStepOdeSolver.cc.

References chargeBuffer_, AbsODERHS::clone(), dim_, dt_, historyBuffer_, lastIntegrated_, rhs_, and runLen_.

160 {
161  if (this != &r)
162  {
163  delete rhs_; rhs_ = 0;
164  dt_ = r.dt_;
165  dim_ = r.dim_;
166  runLen_ = r.runLen_;
170  if (r.rhs_)
171  rhs_ = r.rhs_->clone();
172  }
173  return *this;
174 }
virtual AbsODERHS * clone() const =0
std::vector< double > chargeBuffer_
std::vector< double > historyBuffer_
void ConstantStepOdeSolver::run ( const double *  initialConditions,
unsigned  lenConditions,
double  dt,
unsigned  nSteps 
)

Definition at line 312 of file ConstantStepOdeSolver.cc.

References assert(), dim_, dt, dt_, edm::hlt::Exception, historyBuffer_, i, lastIntegrated_, GetRecoTauVFromDQM_MC_cff::next, rhs_, runLen_, step(), and tree::t.

Referenced by Types.EventID::cppID(), Types.LuminosityBlockID::cppID(), and QIE8Simulator::run().

315 {
316  if (!nSteps || !lenInitialConditions)
317  return;
318  if (!rhs_) throw cms::Exception(
319  "In ConstantStepOdeSolver::run: ODE right hand side has not been set");
320  if (dt <= 0.0) throw cms::Exception(
321  "In ConstantStepOdeSolver::run: can not run backwards in time");
322  assert(initialConditions);
323  dt_ = dt;
324  dim_ = lenInitialConditions;
326  runLen_ = nSteps + 1U;
327  const unsigned sz = (runLen_+1U)*dim_;
328  if (historyBuffer_.size() < sz)
329  historyBuffer_.resize(sz);
330  double* arr = &historyBuffer_[0];
331  for (unsigned i=0; i<lenInitialConditions; ++i)
332  arr[i] = initialConditions[i];
333  double* stepBuffer = arr + runLen_*dim_;
334 
335  for (unsigned i = 0; i < nSteps; ++i, arr += lenInitialConditions)
336  {
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];
342  }
343 }
tuple t
Definition: tree.py:139
float dt
Definition: AMPTWrapper.h:126
int i
Definition: DBlmapReader.cc:9
assert(m_qm.get())
virtual void step(double t, double dt, const double *x, unsigned lenX, double *coordIncrement) const =0
std::vector< double > historyBuffer_
void ConstantStepOdeSolver::setHistory ( double  dt,
const double *  data,
unsigned  dim,
unsigned  runLen 
)

Definition at line 289 of file ConstantStepOdeSolver.cc.

References assert(), dim_, dt, dt_, edm::hlt::Exception, historyBuffer_, i, lastIntegrated_, and runLen_.

Referenced by QIE8Simulator::run().

291 {
292  const unsigned len = dim*runLen;
293  if (!len)
294  return;
295  if (dt <= 0.0) throw cms::Exception(
296  "In ConstantStepOdeSolver::setHistory: can not run backwards in time");
297  assert(data);
298  const unsigned sz = dim*(runLen + 1U);
299  if (historyBuffer_.size() < sz)
300  historyBuffer_.resize(sz);
301  dt_ = dt;
302  dim_ = dim;
303  runLen_ = runLen;
305  double* arr = &historyBuffer_[0];
306  for (unsigned i=0; i<len; ++i)
307  *arr++ = *data++;
308  for (unsigned i=0; i<dim; ++i)
309  *arr++ = 0.0;
310 }
float dt
Definition: AMPTWrapper.h:126
int i
Definition: DBlmapReader.cc:9
assert(m_qm.get())
std::vector< double > historyBuffer_
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void ConstantStepOdeSolver::setRHS ( const AbsODERHS rhs)
inline

Definition at line 33 of file ConstantStepOdeSolver.h.

References AbsODERHS::clone(), and rhs_.

Referenced by QIE8Simulator::setRHS().

34  {
35  delete rhs_;
36  rhs_ = rhs.clone();
37  }
virtual AbsODERHS * clone() const =0
virtual void ConstantStepOdeSolver::step ( double  t,
double  dt,
const double *  x,
unsigned  lenX,
double *  coordIncrement 
) const
privatepure virtual

Implemented in RK4, RK2, and EulerOdeSolver.

Referenced by run().

void ConstantStepOdeSolver::truncateCoordinate ( unsigned  which,
double  minValue,
double  maxValue 
)

Definition at line 176 of file ConstantStepOdeSolver.cc.

References dim_, edm::hlt::Exception, historyBuffer_, i, and runLen_.

Referenced by QIE8Simulator::run().

179 {
180  if (which >= dim_) throw cms::Exception(
181  "In ConstantStepOdeSolver::truncateCoordinate: index out of range");
182  if (minValue > maxValue) throw cms::Exception(
183  "In ConstantStepOdeSolver::truncateCoordinate: invalid truncation range");
184 
185  double* buf = &historyBuffer_[which];
186  for (unsigned i=0; i<runLen_; ++i)
187  {
188  if (buf[dim_*i] < minValue)
189  buf[dim_*i] = minValue;
190  else if (buf[dim_*i] > maxValue)
191  buf[dim_*i] = maxValue;
192  }
193 }
int i
Definition: DBlmapReader.cc:9
std::vector< double > historyBuffer_
void ConstantStepOdeSolver::writeHistory ( std::ostream &  os,
double  dt,
bool  cubic = false 
) const

Definition at line 84 of file ConstantStepOdeSolver.cc.

References dim_, dt, dt_, getCoordinate(), getTime(), i, interpolateCoordinate(), lastMaxT(), methodName(), runLen_, tree::t, and tmax.

Referenced by operator<<().

87 {
88  os << "# " << this->methodName() << '\n';
89  if (dim_ && runLen_)
90  {
91  if (dt == dt_)
92  {
93  for (unsigned ipt=0; ipt<runLen_; ++ipt)
94  {
95  os << getTime(ipt);
96  for (unsigned which=0; which<dim_; ++which)
97  os << ' ' << getCoordinate(which, ipt);
98  os << '\n';
99  }
100  }
101  else
102  {
103  const double tmax = lastMaxT();
104  for (unsigned i=0; ; ++i)
105  {
106  const double t = i*dt;
107  if (t > tmax)
108  break;
109  os << t;
110  for (unsigned which=0; which<dim_; ++which)
111  os << ' ' << interpolateCoordinate(which, t, cubic);
112  os << '\n';
113  }
114  }
115  }
116 }
double getCoordinate(const unsigned which, const unsigned idx) const
tuple t
Definition: tree.py:139
float dt
Definition: AMPTWrapper.h:126
int i
Definition: DBlmapReader.cc:9
double getTime(const unsigned idx) const
virtual const char * methodName() const =0
static const double tmax[3]
double interpolateCoordinate(unsigned which, double t, bool cubic=false) const
void ConstantStepOdeSolver::writeIntegrated ( std::ostream &  os,
unsigned  which,
double  dt,
bool  cubic = false 
) const

Definition at line 118 of file ConstantStepOdeSolver.cc.

References dim_, dt, dt_, getIntegrated(), getTime(), i, interpolateIntegrated(), lastMaxT(), methodName(), runLen_, tree::t, and tmax.

122 {
123  os << "# " << this->methodName() << '\n';
124  if (dim_ && runLen_)
125  {
126  if (dt == dt_)
127  {
128  for (unsigned ipt=0; ipt<runLen_; ++ipt)
129  os << getTime(ipt) << ' ' << getIntegrated(which, ipt) << '\n';
130  }
131  else
132  {
133  const double tmax = lastMaxT();
134  for (unsigned i=0; ; ++i)
135  {
136  const double t = i*dt;
137  if (t > tmax)
138  break;
139  os << t << ' ' << interpolateIntegrated(which, t, cubic) << '\n';
140  }
141  }
142  }
143 }
tuple t
Definition: tree.py:139
float dt
Definition: AMPTWrapper.h:126
int i
Definition: DBlmapReader.cc:9
double interpolateIntegrated(unsigned which, double t, bool cubic=false) const
double getTime(const unsigned idx) const
double getIntegrated(unsigned which, unsigned idx) const
virtual const char * methodName() const =0
static const double tmax[3]

Member Data Documentation

std::vector<double> ConstantStepOdeSolver::chargeBuffer_
private
unsigned ConstantStepOdeSolver::dim_
private
double ConstantStepOdeSolver::dt_
private
std::vector<double> ConstantStepOdeSolver::historyBuffer_
private
unsigned ConstantStepOdeSolver::lastIntegrated_
private
AbsODERHS* ConstantStepOdeSolver::rhs_
protected
unsigned ConstantStepOdeSolver::runLen_
private