COPASI API  4.16.103
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
CInterpolation Class Reference

#include <CInterpolation.h>

Collaboration diagram for CInterpolation:
Collaboration graph
[legend]

Public Member Functions

 CInterpolation ()
 
 CInterpolation (size_t stateNum, size_t reactionNum)
 
CStateRecordgetInterpolationState ()
 
void recordReset ()
 
void recordState (const C_FLOAT64 time, const C_FLOAT64 *y)
 
 ~CInterpolation ()
 

Private Member Functions

void calculateFiringTime ()
 
void calculateState ()
 
C_FLOAT64 interpolation (C_FLOAT64 x)
 

Private Attributes

size_t mBeginRecordIndex
 
size_t mHaveRecordNum
 
CStateRecordmpInterpolationState
 
CStateRecordmpState
 
C_FLOAT64mpX
 
C_FLOAT64mpY
 
bool mShiftBeginIndex
 
size_t mStateNum
 

Friends

void printInterpolation (const CInterpolation &interp)
 

Detailed Description

Definition at line 102 of file CInterpolation.h.

Constructor & Destructor Documentation

CInterpolation::CInterpolation ( )

Default Constructor

Definition at line 95 of file CInterpolation.cpp.

95  :
96  mpX(NULL),
97  mpY(NULL),
98  mStateNum(0),
100  mpState(NULL),
101  mHaveRecordNum(0),
102  mpInterpolationState(NULL),
103  mShiftBeginIndex(false)
104 {}
CStateRecord * mpInterpolationState
CStateRecord * mpState
size_t mBeginRecordIndex
C_FLOAT64 * mpY
C_FLOAT64 * mpX
CInterpolation::CInterpolation ( size_t  stateNum,
size_t  reactionNum 
)

Assignment Constructor

Definition at line 106 of file CInterpolation.cpp.

References mpInterpolationState, and mpState.

106  :
107  mpX(new C_FLOAT64[stateNum]),
108  mpY(new C_FLOAT64[stateNum]),
109  mStateNum(stateNum),
111  mHaveRecordNum(0),
112  mShiftBeginIndex(false)
113 {
114  mpInterpolationState = new CStateRecord(speciesNum);
115 
116  mpState = static_cast< CStateRecord* >
117  (operator new[](sizeof(CStateRecord) * stateNum));
118 
119  for (size_t i = 0; i < stateNum; i++)
120  new(&mpState[i]) CStateRecord(speciesNum);
121 
122  return;
123 }
CStateRecord * mpInterpolationState
CStateRecord * mpState
size_t mBeginRecordIndex
C_FLOAT64 * mpY
#define C_FLOAT64
Definition: copasi.h:92
C_FLOAT64 * mpX
CInterpolation::~CInterpolation ( )

Destructor

Definition at line 125 of file CInterpolation.cpp.

References mpInterpolationState, mpState, mpX, mpY, mStateNum, pdelete, pdeletev, and CStateRecord::~CStateRecord().

126 {
127  pdeletev(mpX);
128  pdeletev(mpY);
129 
131 
132  for (int i = mStateNum - 1; i >= 0; i--)
133  {
134  mpState[i].~CStateRecord();
135  }
136 
137  if (mpState != NULL)
138  operator delete[](mpState);
139 }
CStateRecord * mpInterpolationState
#define pdelete(p)
Definition: copasi.h:215
CStateRecord * mpState
#define pdeletev(p)
Definition: copasi.h:216
C_FLOAT64 * mpY
C_FLOAT64 * mpX

Member Function Documentation

void CInterpolation::calculateFiringTime ( )
private

Calculate time when slow reaction fires

Definition at line 232 of file CInterpolation.cpp.

References C_FLOAT64, CStateRecord::getArray(), CStateRecord::getSlowPropensitySum(), CStateRecord::getTime(), interpolation(), mBeginRecordIndex, mHaveRecordNum, mpInterpolationState, mpState, mpX, mpY, and mStateNum.

Referenced by getInterpolationState().

233 {
234  size_t i = mBeginRecordIndex;
235 
236  //(1)Load time into mpY
237  //(2)Load sum of slow reaction propensities
238  // into mpX
239 
240  for (size_t j = 0; j < mHaveRecordNum; j++)
241  {
242  mpY[j] = mpState[i].getTime();
243  mpX[j] = mpState[i].getSlowPropensitySum();
244 
245  if (++i > (mStateNum - 1))
246  i -= mStateNum;
247  }
248 
249  //(3)do interpolation at propensity=0
251  pArray[0] = interpolation(0.0);
252 }
CStateRecord * mpInterpolationState
CStateRecord * mpState
size_t mBeginRecordIndex
const C_FLOAT64 & getSlowPropensitySum() const
C_FLOAT64 interpolation(C_FLOAT64 x)
C_FLOAT64 * getArray() const
const C_FLOAT64 & getTime() const
C_FLOAT64 * mpY
#define C_FLOAT64
Definition: copasi.h:92
C_FLOAT64 * mpX
void CInterpolation::calculateState ( )
private

Calculate Model State at event time

Definition at line 254 of file CInterpolation.cpp.

References C_FLOAT64, CStateRecord::getArray(), CStateRecord::getArrayLen(), CStateRecord::getTime(), interpolation(), mBeginRecordIndex, mHaveRecordNum, mpInterpolationState, mpState, mpX, mpY, and mStateNum.

Referenced by getInterpolationState().

255 {
256  C_FLOAT64 *pInterArray = mpInterpolationState->getArray();
257  C_FLOAT64 **ppArray = new C_FLOAT64*[mHaveRecordNum];
259 
260  //(1)Load time into array mpX
261  //(2)Load pointers of objects CStateRecord into ppArray
262  size_t i = mBeginRecordIndex;
263 
264  for (size_t j = 0; j < mHaveRecordNum; j++)
265  {
266  ppArray[j] = mpState[i].getArray();
267  mpX[j] = mpState[i].getTime();
268 
269  if (++i > mStateNum - 1)
270  i -= mStateNum;
271  }
272 
273  //(3)Load propensities into mpY
274  //(4)Do interpolation
275  size_t speciesNum = (mpInterpolationState->getArrayLen()) - 2;
276 
277  for (size_t species = 1; species <= speciesNum; species++)
278  {
279  for (size_t j = 0; j < mHaveRecordNum; j++)
280  mpY[j] = ppArray[j][species];
281 
282  pInterArray[species] = interpolation(time);
283  }
284 }
CStateRecord * mpInterpolationState
CStateRecord * mpState
size_t mBeginRecordIndex
C_FLOAT64 interpolation(C_FLOAT64 x)
C_FLOAT64 * getArray() const
const C_FLOAT64 & getTime() const
C_FLOAT64 * mpY
#define C_FLOAT64
Definition: copasi.h:92
C_FLOAT64 * mpX
const size_t & getArrayLen() const
CStateRecord * CInterpolation::getInterpolationState ( )

Retrieve the model State at the slow reaction firing time by call calculateFiringTime() and calculateState()

Returns
CStateRecord mInterpolationState

Definition at line 286 of file CInterpolation.cpp.

References calculateFiringTime(), calculateState(), and mpInterpolationState.

Referenced by CHybridMethodODE45::doInverseInterpolation().

287 {
289  calculateState();
290  return mpInterpolationState;
291 }
CStateRecord * mpInterpolationState
void calculateFiringTime()
C_FLOAT64 CInterpolation::interpolation ( C_FLOAT64  x)
private

Calculate Interpolation Value

Parameters
C_FLOAT64x

Definition at line 184 of file CInterpolation.cpp.

References C_FLOAT64, mHaveRecordNum, mpX, and mpY.

Referenced by calculateFiringTime(), and calculateState().

185 {
186  //Before use this function, data have been stored in
187  //arraies mpX, mpY. Lengths of array is given by
188  //mHaveRecordNum
189 
190  if ((x > mpX[mHaveRecordNum - 1])
191  || (x < mpX[0])) //If x is within the range
192  //Show Error !!!
193  std::cout << "x " << x << " is out of range" << std::endl;
194 
195  if (mHaveRecordNum == 1)
196  return mpY[0]; //only one point recorded
197 
198  size_t i, j;
199 
200  for (i = 0; i < mHaveRecordNum; i++) //x is in *mpX
201  {
202  if (x == mpX[i])
203  return mpY[i];
204  }
205 
206  //Calculate interpolation value
207  C_FLOAT64 numer, tmpNumer = 1;
208  C_FLOAT64 denom;
209 
210  for (i = 0; i < mHaveRecordNum; i++)
211  tmpNumer *= x - mpX[i];
212 
213  C_FLOAT64 y = 0;
214 
215  for (i = 0; i < mHaveRecordNum; i++)
216  {
217  numer = tmpNumer / (x - mpX[i]);
218  denom = 1;
219 
220  for (j = 0; j < mHaveRecordNum; j++)
221  {
222  if (i != j)
223  denom *= mpX[i] - mpX[j];
224  }
225 
226  y += mpY[i] * numer / denom;
227  }
228 
229  return y;
230 }
C_FLOAT64 * mpY
#define C_FLOAT64
Definition: copasi.h:92
C_FLOAT64 * mpX
void CInterpolation::recordReset ( )

Reset the record

Definition at line 177 of file CInterpolation.cpp.

References mBeginRecordIndex, mHaveRecordNum, and mShiftBeginIndex.

Referenced by CHybridMethodODE45::doInverseInterpolation().

178 {
179  mBeginRecordIndex = 0;
180  mHaveRecordNum = 0;
181  mShiftBeginIndex = false;
182 }
size_t mBeginRecordIndex
void CInterpolation::recordState ( const C_FLOAT64  time,
const C_FLOAT64 y 
)

Load the New State const C_FLOAT64 time, const unsigned C_INT32 len const C_FLOAT54 *y

Definition at line 141 of file CInterpolation.cpp.

References C_FLOAT64, CStateRecord::getArray(), CStateRecord::getArrayLen(), mBeginRecordIndex, mHaveRecordNum, mpState, mShiftBeginIndex, and mStateNum.

Referenced by CHybridMethodODE45::doInverseInterpolation().

143 {
144  mHaveRecordNum++;
145 
147  {
149 
150  if (!mShiftBeginIndex)
151  mShiftBeginIndex = true;
152  }
153 
154  if (mShiftBeginIndex)
156 
157  size_t newStateIndex = mBeginRecordIndex
158  + mHaveRecordNum - 1;
159 
160  newStateIndex %= mStateNum;
161  //std::cout << "newStateIndex: " << newStateIndex << std::endl;
162 
163  C_FLOAT64 *pArray = mpState[newStateIndex].getArray();
164  const size_t size = mpState[newStateIndex].getArrayLen();
165 
166  pArray[0] = time;
167 
168  for (size_t i = 1; i < size; i++, y++)
169  {
170  ++pArray;
171  *pArray = *y;
172  }
173 
174  return;
175 }
CStateRecord * mpState
size_t mBeginRecordIndex
C_FLOAT64 * getArray() const
#define C_FLOAT64
Definition: copasi.h:92
const size_t & getArrayLen() const

Friends And Related Function Documentation

void printInterpolation ( const CInterpolation interp)
friend

Friend Function for Debug

Definition at line 294 of file CInterpolation.cpp.

295 {
296  std::cout << "State Num: " << interp.mStateNum << std::endl;
297  std::cout << "Record Num: " << interp.mHaveRecordNum << std::endl;
298  std::cout << "Begin Record Index: " << interp.mBeginRecordIndex << std::endl;
299  std::cout << "Shift or not: ";
300 
301  if (interp.mShiftBeginIndex)
302  std::cout << "Yes" << std::endl;
303  else
304  std::cout << "No" << std::endl;
305 
306  int site;
307 
308  for (size_t i = 0; i < interp.mHaveRecordNum; i++)
309  {
310  std::cout << "Record #:" << i << std::endl;
311  site = (interp.mBeginRecordIndex + i) % interp.mStateNum;
312  printRecord(interp.mpState[site]);
313  }
314 
315  std::cout << "Finish, aha" << std::endl;
316  return;
317 }
CStateRecord * mpState
size_t mBeginRecordIndex
void printRecord(const CStateRecord &record)

Member Data Documentation

size_t CInterpolation::mBeginRecordIndex
private

An integer index indicating which state is the first available one for interpolation

Definition at line 199 of file CInterpolation.h.

Referenced by calculateFiringTime(), calculateState(), printInterpolation(), recordReset(), and recordState().

size_t CInterpolation::mHaveRecordNum
private

An integer indicating how many state has been recorded

Definition at line 204 of file CInterpolation.h.

Referenced by calculateFiringTime(), calculateState(), interpolation(), printInterpolation(), recordReset(), and recordState().

CStateRecord* CInterpolation::mpInterpolationState
private

A pointer of CStateRecord Object recording the state of model at slow reaction firing time calculated by interpolation

Definition at line 178 of file CInterpolation.h.

Referenced by calculateFiringTime(), calculateState(), CInterpolation(), getInterpolationState(), and ~CInterpolation().

CStateRecord* CInterpolation::mpState
private

Pointer to an array of class CStateRecord

Definition at line 171 of file CInterpolation.h.

Referenced by calculateFiringTime(), calculateState(), CInterpolation(), printInterpolation(), recordState(), and ~CInterpolation().

C_FLOAT64* CInterpolation::mpX
private

A C_FLOAT64 pointer for interpolation array x

Definition at line 183 of file CInterpolation.h.

Referenced by calculateFiringTime(), calculateState(), interpolation(), and ~CInterpolation().

C_FLOAT64* CInterpolation::mpY
private

A C_FLOAT64 pointer for interpolation array y

Definition at line 188 of file CInterpolation.h.

Referenced by calculateFiringTime(), calculateState(), interpolation(), and ~CInterpolation().

bool CInterpolation::mShiftBeginIndex
private

A Bool variable indicating whether the mBeginRecordIndex should be shift

Definition at line 210 of file CInterpolation.h.

Referenced by printInterpolation(), recordReset(), and recordState().

size_t CInterpolation::mStateNum
private

Length of Vector mState

Definition at line 193 of file CInterpolation.h.

Referenced by calculateFiringTime(), calculateState(), printInterpolation(), recordState(), and ~CInterpolation().


The documentation for this class was generated from the following files: