MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MarkovGslSolver Class Reference

#include <MarkovGslSolver.h>

+ Collaboration diagram for MarkovGslSolver:

Public Member Functions

double getAbsoluteAccuracy () const
 
double getInternalDt () const
 
bool getIsInitialized () const
 
string getMethod () const
 
double getRelativeAccuracy () const
 
void handleQ (vector< vector< double > >)
 
void init (vector< double >)
 
 MarkovGslSolver ()
 
void process (const Eref &e, ProcPtr info)
 
void reinit (const Eref &e, ProcPtr info)
 
void setAbsoluteAccuracy (double value)
 
void setInternalDt (double value)
 
void setMethod (string method)
 
void setRelativeAccuracy (double value)
 
 ~MarkovGslSolver ()
 

Static Public Member Functions

static const CinfoinitCinfo ()
 

Static Private Member Functions

static int evalSystem (double, const double *, double *, void *)
 

Private Attributes

double absAccuracy_
 
gsl_odeiv_control * gslControl_
 
gsl_odeiv_evolve * gslEvolve_
 
gsl_odeiv_step * gslStep_
 
const gsl_odeiv_step_type * gslStepType_
 
gsl_odeiv_system gslSys_
 
vector< double > initialState_
 
double internalStepSize_
 
bool isInitialized_
 
string method_
 
unsigned int nVars_
 
vector< vector< double > > Q_
 
double relAccuracy_
 
vector< double > state_
 
double * stateGsl_
 

Detailed Description

Definition at line 25 of file MarkovGslSolver.h.

Constructor & Destructor Documentation

MarkovGslSolver::MarkovGslSolver ( )

Definition at line 127 of file MarkovGslSolver.cpp.

References absAccuracy_, gslControl_, gslEvolve_, gslStep_, gslStepType_, internalStepSize_, isInitialized_, method_, nVars_, relAccuracy_, and stateGsl_.

128 {
129  isInitialized_ = 0;
130  method_ = "rk5";
131  gslStepType_ = gsl_odeiv_step_rkf45;
132  gslStep_ = 0;
133  nVars_ = 0;
134  absAccuracy_ = 1.0e-8;
135  relAccuracy_ = 1.0e-8;
136  internalStepSize_ = 1.0e-6;
137  stateGsl_ = 0;
138  gslEvolve_ = NULL;
139  gslControl_ = NULL;
140 }
gsl_odeiv_step * gslStep_
double internalStepSize_
gsl_odeiv_evolve * gslEvolve_
const gsl_odeiv_step_type * gslStepType_
gsl_odeiv_control * gslControl_
unsigned int nVars_
MarkovGslSolver::~MarkovGslSolver ( )

Definition at line 142 of file MarkovGslSolver.cpp.

References gslControl_, gslEvolve_, gslStep_, and stateGsl_.

143 {
144  if ( gslEvolve_ )
145  gsl_odeiv_evolve_free( gslEvolve_ );
146  if ( gslControl_ )
147  gsl_odeiv_control_free( gslControl_ );
148  if ( gslStep_ )
149  gsl_odeiv_step_free( gslStep_ );
150 
151  if ( stateGsl_ )
152  delete[] stateGsl_;
153 }
gsl_odeiv_step * gslStep_
gsl_odeiv_evolve * gslEvolve_
gsl_odeiv_control * gslControl_

Member Function Documentation

int MarkovGslSolver::evalSystem ( double  t,
const double *  state,
double *  f,
void *  params 
)
staticprivate

Definition at line 155 of file MarkovGslSolver.cpp.

Referenced by init().

156 {
157  vector< vector< double > >* Q = static_cast< vector< vector< double > >* >( params );
158  unsigned int nVars = Q->size();
159 
160  //Matrix being accessed along columns, which is a very bad thing in terms of
161  //cache optimality. Transposing the matrix during reinit() would be a good idea.
162  for ( unsigned int i = 0; i < nVars; ++i)
163  {
164  f[i] = 0;
165  for ( unsigned int j = 0; j < nVars; ++j)
166  f[i] += state[j] * ((*Q)[j][i]);
167  }
168 
169  return GSL_SUCCESS;
170 }

+ Here is the caller graph for this function:

double MarkovGslSolver::getAbsoluteAccuracy ( ) const

Definition at line 229 of file MarkovGslSolver.cpp.

References absAccuracy_.

Referenced by initCinfo().

230 {
231  return absAccuracy_;
232 }

+ Here is the caller graph for this function:

double MarkovGslSolver::getInternalDt ( ) const

Definition at line 238 of file MarkovGslSolver.cpp.

References internalStepSize_.

Referenced by initCinfo().

239 {
240  return internalStepSize_;
241 }
double internalStepSize_

+ Here is the caller graph for this function:

bool MarkovGslSolver::getIsInitialized ( ) const

Definition at line 176 of file MarkovGslSolver.cpp.

References isInitialized_.

Referenced by initCinfo().

177 {
178  return isInitialized_;
179 }

+ Here is the caller graph for this function:

string MarkovGslSolver::getMethod ( ) const

Definition at line 181 of file MarkovGslSolver.cpp.

References method_.

Referenced by initCinfo().

182 {
183  return method_;
184 }

+ Here is the caller graph for this function:

double MarkovGslSolver::getRelativeAccuracy ( ) const

Definition at line 219 of file MarkovGslSolver.cpp.

References relAccuracy_.

Referenced by initCinfo().

220 {
221  return relAccuracy_;
222 }

+ Here is the caller graph for this function:

void MarkovGslSolver::handleQ ( vector< vector< double > >  )

Definition at line 347 of file MarkovGslSolver.cpp.

References Q_.

Referenced by initCinfo().

348 {
349  Q_ = Q;
350 }
vector< vector< double > > Q_

+ Here is the caller graph for this function:

void MarkovGslSolver::init ( vector< double >  initialState)

Definition at line 253 of file MarkovGslSolver.cpp.

References absAccuracy_, evalSystem(), gslControl_, gslEvolve_, gslStep_, gslStepType_, gslSys_, initialState_, isInitialized_, nVars_, Q_, relAccuracy_, resize(), state_, and stateGsl_.

Referenced by initCinfo().

254 {
255  nVars_ = initialState.size();
256 
257  if ( stateGsl_ == 0 )
258  stateGsl_ = new double[ nVars_ ];
259 
260  state_ = initialState;
261  initialState_ = initialState;
262 
263  Q_.resize( nVars_ );
264 
265  for ( unsigned int i = 0; i < nVars_; ++i )
266  Q_[i].resize( nVars_, 0.0 );
267 
268  isInitialized_ = 1;
269 
270  assert( gslStepType_ != 0 );
271  if ( gslStep_ )
272  gsl_odeiv_step_free(gslStep_);
273 
274  gslStep_ = gsl_odeiv_step_alloc( gslStepType_, nVars_ );
275  assert( gslStep_ != 0 );
276 
277  if ( !gslEvolve_ )
278  gslEvolve_ = gsl_odeiv_evolve_alloc(nVars_);
279  else
280  gsl_odeiv_evolve_reset(gslEvolve_);
281 
282  assert(gslEvolve_ != 0);
283 
284  if ( !gslControl_ )
285  gslControl_ = gsl_odeiv_control_y_new( absAccuracy_, relAccuracy_ );
286  else
287  gsl_odeiv_control_init(gslControl_,absAccuracy_, relAccuracy_, 1, 0);
288 
289  assert(gslControl_!= 0);
290 
292  gslSys_.jacobian = 0;
293  gslSys_.dimension = nVars_;
294  gslSys_.params = static_cast< void * >( &Q_ );
295 }
static int evalSystem(double, const double *, double *, void *)
gsl_odeiv_step * gslStep_
vector< vector< double > > Q_
vector< double > state_
gsl_odeiv_system gslSys_
gsl_odeiv_evolve * gslEvolve_
const gsl_odeiv_step_type * gslStepType_
vector< vector< T > > resize(vector< vector< T > >table, unsigned int n, T init)
gsl_odeiv_control * gslControl_
unsigned int nVars_
vector< double > initialState_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const Cinfo * MarkovGslSolver::initCinfo ( )
static

Definition at line 22 of file MarkovGslSolver.cpp.

References getAbsoluteAccuracy(), getInternalDt(), getIsInitialized(), getMethod(), getRelativeAccuracy(), handleQ(), init(), Neutral::initCinfo(), MarkovGslSolverCinfo, process(), reinit(), setAbsoluteAccuracy(), setInternalDt(), setMethod(), setRelativeAccuracy(), and stateOut().

23 {
25  // Field definitions
28  "isInitialized",
29  "True if the message has come in to set solver parameters.",
31  );
32  static ValueFinfo< MarkovGslSolver, string > method( "method",
33  "Numerical method to use.",
36  );
37  static ValueFinfo< MarkovGslSolver, double > relativeAccuracy(
38  "relativeAccuracy",
39  "Accuracy criterion",
42  );
43  static ValueFinfo< MarkovGslSolver, double > absoluteAccuracy(
44  "absoluteAccuracy",
45  "Another accuracy criterion",
48  );
49  static ValueFinfo< MarkovGslSolver, double > internalDt(
50  "internalDt",
51  "internal timestep to use.",
54  );
55 
57  // DestFinfo definitions
59  static DestFinfo init( "init",
60  "Initialize solver parameters.",
61  new OpFunc1< MarkovGslSolver, vector< double > >
63  );
64 
65  static DestFinfo handleQ( "handleQ",
66  "Handles information regarding the instantaneous rate matrix from "
67  "the MarkovRateTable class.",
68  new OpFunc1< MarkovGslSolver, vector< vector< double > > >( &MarkovGslSolver::handleQ) );
69 
70  static DestFinfo process( "process",
71  "Handles process call",
73  static DestFinfo reinit( "reinit",
74  "Handles reinit call",
77  // Shared definitions
79  static Finfo* procShared[] = {
80  &process, &reinit
81  };
82  static SharedFinfo proc( "proc",
83  "Shared message for process and reinit",
84  procShared, sizeof( procShared ) / sizeof( const Finfo* )
85  );
86 
87  static Finfo* MarkovGslFinfos[] =
88  {
89  &isInitialized, // ValueFinfo
90  &method, // ValueFinfo
91  &relativeAccuracy, // ValueFinfo
92  &absoluteAccuracy, // ValueFinfo
93  &internalDt, // ValueFinfo
94  &init, // DestFinfo
95  &handleQ, // DestFinfo
96  &proc, // SharedFinfo
97  stateOut(), // SrcFinfo
98  };
99 
100  static string doc[] =
101  {
102  "Name", "MarkovGslSolver",
103  "Author", "Vishaka Datta S, 2011, NCBS",
104  "Description", "Solver for Markov Channel."
105  };
106 
107  static Dinfo< MarkovGslSolver > dinfo;
109  "MarkovGslSolver",
111  MarkovGslFinfos,
112  sizeof(MarkovGslFinfos)/sizeof(Finfo *),
113  &dinfo,
114  doc,
115  sizeof(doc) / sizeof(string)
116  );
117 
118  return &MarkovGslSolverCinfo;
119 }
void setInternalDt(double value)
void reinit(const Eref &e, ProcPtr info)
static const Cinfo * MarkovGslSolverCinfo
Definition: Dinfo.h:60
void setMethod(string method)
double getInternalDt() const
void init(vector< double >)
void process(const Eref &e, ProcPtr info)
static SrcFinfo1< vector< double > > * stateOut()
void setRelativeAccuracy(double value)
Definition: OpFunc.h:27
double getAbsoluteAccuracy() const
string getMethod() const
void handleQ(vector< vector< double > >)
bool getIsInitialized() const
void setAbsoluteAccuracy(double value)
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
Definition: Cinfo.h:18
double getRelativeAccuracy() const
Definition: Finfo.h:12

+ Here is the call graph for this function:

void MarkovGslSolver::process ( const Eref e,
ProcPtr  info 
)

Definition at line 300 of file MarkovGslSolver.cpp.

References ProcInfo::currTime, ProcInfo::dt, gslControl_, gslEvolve_, gslStep_, gslSys_, internalStepSize_, nVars_, state_, stateGsl_, and stateOut().

Referenced by initCinfo().

301 {
302  double nextt = info->currTime + info->dt;
303  double t = info->currTime;
304  double sum = 0;
305 
306  for ( unsigned int i = 0; i < nVars_; ++i )
307  stateGsl_[i] = state_[i];
308 
309  while ( t < nextt ) {
310  int status = gsl_odeiv_evolve_apply (
312  &t, nextt,
314 
315  //Simple idea borrowed from Dieter Jaeger's implementation of a Markov
316  //channel to deal with potential round-off error.
317  sum = 0;
318  for ( unsigned int i = 0; i < nVars_; i++ )
319  sum += stateGsl_[i];
320 
321  for ( unsigned int i = 0; i < nVars_; i++ )
322  stateGsl_[i] /= sum;
323 
324  if ( status != GSL_SUCCESS )
325  break;
326  }
327 
328  for ( unsigned int i = 0; i < nVars_; ++i )
329  state_[i] = stateGsl_[i];
330 
331  stateOut()->send( e, state_ );
332 }
double currTime
Definition: ProcInfo.h:19
gsl_odeiv_step * gslStep_
vector< double > state_
double internalStepSize_
gsl_odeiv_system gslSys_
gsl_odeiv_evolve * gslEvolve_
static SrcFinfo1< vector< double > > * stateOut()
double dt
Definition: ProcInfo.h:18
gsl_odeiv_control * gslControl_
unsigned int nVars_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MarkovGslSolver::reinit ( const Eref e,
ProcPtr  info 
)

Definition at line 334 of file MarkovGslSolver.cpp.

References initialState_, state_, and stateOut().

Referenced by initCinfo().

335 {
337  if ( initialState_.empty() )
338  {
339  cerr << "MarkovGslSolver::reinit : "
340  "Initial state has not been set. Solver has not been initialized."
341  "Call init() before running.\n";
342  }
343 
344  stateOut()->send( e, state_ );
345 }
vector< double > state_
static SrcFinfo1< vector< double > > * stateOut()
vector< double > initialState_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MarkovGslSolver::setAbsoluteAccuracy ( double  value)

Definition at line 233 of file MarkovGslSolver.cpp.

References absAccuracy_, and value.

Referenced by initCinfo().

234 {
236 }
uint32_t value
Definition: moosemodule.h:42

+ Here is the caller graph for this function:

void MarkovGslSolver::setInternalDt ( double  value)

Definition at line 243 of file MarkovGslSolver.cpp.

References internalStepSize_, and value.

Referenced by initCinfo().

244 {
246 }
uint32_t value
Definition: moosemodule.h:42
double internalStepSize_

+ Here is the caller graph for this function:

void MarkovGslSolver::setMethod ( string  method)

Definition at line 186 of file MarkovGslSolver.cpp.

References gslStepType_, and method_.

Referenced by initCinfo().

187 {
188  method_ = method;
189  gslStepType_ = 0;
190 
191  if ( method == "rk2" ) {
192  gslStepType_ = gsl_odeiv_step_rk2;
193  } else if ( method == "rk4" ) {
194  gslStepType_ = gsl_odeiv_step_rk4;
195  } else if ( method == "rk5" ) {
196  gslStepType_ = gsl_odeiv_step_rkf45;
197  } else if ( method == "rkck" ) {
198  gslStepType_ = gsl_odeiv_step_rkck;
199  } else if ( method == "rk8pd" ) {
200  gslStepType_ = gsl_odeiv_step_rk8pd;
201  } else if ( method == "rk2imp" ) {
202  gslStepType_ = gsl_odeiv_step_rk2imp;
203  } else if ( method == "rk4imp" ) {
204  gslStepType_ = gsl_odeiv_step_rk4imp;
205  } else if ( method == "bsimp" ) {
206  gslStepType_ = gsl_odeiv_step_rk4imp;
207  cout << "Warning: implicit Bulirsch-Stoer method not yet implemented: needs Jacobian\n";
208  } else if ( method == "gear1" ) {
209  gslStepType_ = gsl_odeiv_step_gear1;
210  } else if ( method == "gear2" ) {
211  gslStepType_ = gsl_odeiv_step_gear2;
212  } else {
213  cout << "Warning: MarkovGslSolver::innerSetMethod: method '" <<
214  method << "' not known, using rk5\n";
215  gslStepType_ = gsl_odeiv_step_rkf45;
216  }
217 }
const gsl_odeiv_step_type * gslStepType_

+ Here is the caller graph for this function:

void MarkovGslSolver::setRelativeAccuracy ( double  value)

Definition at line 224 of file MarkovGslSolver.cpp.

References relAccuracy_, and value.

Referenced by initCinfo().

225 {
227 }
uint32_t value
Definition: moosemodule.h:42

+ Here is the caller graph for this function:

Member Data Documentation

double MarkovGslSolver::absAccuracy_
private

Definition at line 58 of file MarkovGslSolver.h.

Referenced by getAbsoluteAccuracy(), init(), MarkovGslSolver(), and setAbsoluteAccuracy().

gsl_odeiv_control* MarkovGslSolver::gslControl_
private

Definition at line 72 of file MarkovGslSolver.h.

Referenced by init(), MarkovGslSolver(), process(), and ~MarkovGslSolver().

gsl_odeiv_evolve* MarkovGslSolver::gslEvolve_
private

Definition at line 73 of file MarkovGslSolver.h.

Referenced by init(), MarkovGslSolver(), process(), and ~MarkovGslSolver().

gsl_odeiv_step* MarkovGslSolver::gslStep_
private

Definition at line 71 of file MarkovGslSolver.h.

Referenced by init(), MarkovGslSolver(), process(), and ~MarkovGslSolver().

const gsl_odeiv_step_type* MarkovGslSolver::gslStepType_
private

Definition at line 70 of file MarkovGslSolver.h.

Referenced by init(), MarkovGslSolver(), and setMethod().

gsl_odeiv_system MarkovGslSolver::gslSys_
private

Definition at line 74 of file MarkovGslSolver.h.

Referenced by init(), and process().

vector< double > MarkovGslSolver::initialState_
private

Definition at line 67 of file MarkovGslSolver.h.

Referenced by init(), and reinit().

double MarkovGslSolver::internalStepSize_
private

Definition at line 60 of file MarkovGslSolver.h.

Referenced by getInternalDt(), MarkovGslSolver(), process(), and setInternalDt().

bool MarkovGslSolver::isInitialized_
private

Definition at line 56 of file MarkovGslSolver.h.

Referenced by getIsInitialized(), init(), and MarkovGslSolver().

string MarkovGslSolver::method_
private

Definition at line 57 of file MarkovGslSolver.h.

Referenced by getMethod(), MarkovGslSolver(), and setMethod().

unsigned int MarkovGslSolver::nVars_
private

Definition at line 65 of file MarkovGslSolver.h.

Referenced by init(), MarkovGslSolver(), and process().

vector< vector< double > > MarkovGslSolver::Q_
private

Definition at line 68 of file MarkovGslSolver.h.

Referenced by handleQ(), and init().

double MarkovGslSolver::relAccuracy_
private

Definition at line 59 of file MarkovGslSolver.h.

Referenced by getRelativeAccuracy(), init(), MarkovGslSolver(), and setRelativeAccuracy().

vector< double > MarkovGslSolver::state_
private

Definition at line 66 of file MarkovGslSolver.h.

Referenced by init(), process(), and reinit().

double* MarkovGslSolver::stateGsl_
private

Definition at line 61 of file MarkovGslSolver.h.

Referenced by init(), MarkovGslSolver(), process(), and ~MarkovGslSolver().


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