36#include "OdeSolution.hpp"
40#include "ColumnDataWriter.hpp"
45#if CHASTE_SUNDIALS_VERSION >= 60000
46#include "CvodeContextManager.hpp"
50 : mNumberOfTimeSteps(0u),
51 mpOdeSystemInformation()
65 mTimes.reserve(numTimeSteps+1);
77 std::vector<double> answer;
78 answer.reserve(
mTimes.size());
80 for (
unsigned i=0; i<
mTimes.size(); ++i)
102 EXCEPTION(
"Invalid index passed to ""GetVariableAtIndex()"".");
106 answer.push_back(temp_number);
137template<
typename VECTOR>
146template<
typename VECTOR>
154 for (
unsigned i=0; i<num_params; ++i)
165 assert(pOdeSystem !=
nullptr);
170 for (
unsigned i=0; i<
mTimes.size(); i++)
181 assert(pOdeSystem !=
nullptr);
184 const unsigned num_solutions =
mSolutions.size();
185 assert(
mTimes.size() == num_solutions);
187#if CHASTE_SUNDIALS_VERSION >= 60000
188 N_Vector state_vars = num_solutions > 0 ? N_VNew_Serial(
mSolutions[0].size(), CvodeContextManager::Instance()->GetSundialsContext()) :
nullptr;
190 N_Vector state_vars = num_solutions > 0 ? N_VNew_Serial(
mSolutions[0].size()) :
nullptr;
192 for (
unsigned i=0; i<num_solutions; i++)
208 std::string baseResultsFilename,
209 std::string timeUnits,
210 unsigned stepsPerRow,
213 bool includeDerivedQuantities)
215 assert(stepsPerRow > 0);
216 assert(
mTimes.size() > 0);
221 includeDerivedQuantities =
false;
224 if (includeDerivedQuantities)
228 EXCEPTION(
"You must first call ""CalculateDerivedQuantitiesAndParameters()"" in order to write derived quantities.");
233 ColumnDataWriter writer(directoryName, baseResultsFilename, cleanDirectory, precision);
252 std::vector<int> var_ids;
253 var_ids.reserve(num_vars);
256 for (
unsigned i=0; i<num_vars; i++)
264 for (
unsigned i=0; i<num_vars; i++)
266 std::stringstream string_stream;
267 string_stream <<
"var_" << i;
268 var_ids.push_back(writer.
DefineVariable(string_stream.str(),
""));
272 if (includeDerivedQuantities)
274 var_ids.reserve(num_vars + num_params + num_derived_quantities);
275 for (
unsigned i=0; i<num_params; ++i)
280 for (
unsigned i=0; i<num_derived_quantities; i++)
294 for (
unsigned i=0; i<
mSolutions.size(); i+=stepsPerRow)
297 for (
unsigned j=0; j<num_vars; j++)
301 if (includeDerivedQuantities)
303 for (
unsigned j=0; j<num_params; ++j)
307 for (
unsigned j=0; j<num_derived_quantities; j++)
#define EXCEPTION(message)
void DeleteVector(VECTOR &rVec)
void CopyFromStdVector(const std::vector< double > &rSrc, VECTOR &rDest)
void CopyToStdVector(const VECTOR &rSrc, std::vector< double > &rDest)
virtual VECTOR ComputeDerivedQuantities(double time, const VECTOR &rState)
double GetParameter(unsigned index) const
boost::shared_ptr< const AbstractOdeSystemInformation > GetSystemInformation() const
unsigned GetNumberOfDerivedQuantities() const
unsigned GetNumberOfParameters() const
void SetCommentForInfoFile(std::string comment)
virtual void EndDefineMode()
virtual void AdvanceAlongUnlimitedDimension()
int DefineVariable(const std::string &rVariableName, const std::string &rVariableUnits)
int DefineUnlimitedDimension(const std::string &rDimensionName, const std::string &rDimensionUnits)
virtual void PutVariable(int variableID, double variableValue, long dimensionPosition=-1)
std::vector< double > mParameters
boost::shared_ptr< const AbstractOdeSystemInformation > mpOdeSystemInformation
std::vector< double > GetAnyVariable(const std::string &rName) const
std::vector< double > & rGetParameters(AbstractParameterisedSystem< VECTOR > *pOdeSystem)
void SetNumberOfTimeSteps(unsigned numTimeSteps)
std::vector< double > mTimes
void CalculateDerivedQuantitiesAndParameters(AbstractParameterisedSystem< VECTOR > *pOdeSystem)
unsigned GetNumberOfTimeSteps() const
std::vector< std::vector< double > > & rGetSolutions()
unsigned mNumberOfTimeSteps
std::vector< double > GetVariableAtIndex(unsigned index) const
void WriteToFile(std::string directoryName, std::string baseResultsFilename, std::string timeUnits, unsigned stepsPerRow=1, bool cleanDirectory=true, unsigned precision=8, bool includeDerivedQuantities=false)
std::vector< double > & rGetTimes()
void SetOdeSystemInformation(boost::shared_ptr< const AbstractOdeSystemInformation > pOdeSystemInfo)
std::vector< std::vector< double > > & rGetDerivedQuantities(AbstractParameterisedSystem< std::vector< double > > *pOdeSystem)
std::vector< std::vector< double > > mSolutions
std::vector< std::vector< double > > mDerivedQuantities