Chaste Commit::29c3c4ab2bee00ddd311a035a1e522c03cbe928a
CvodeAdaptor.hpp
1/*
2
3Copyright (c) 2005-2026, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#ifndef _CVODEADAPTOR_HPP_
37#define _CVODEADAPTOR_HPP_
38
39#include <memory>
40#include <vector>
41
42#include <boost/serialization/base_object.hpp>
44
45#include "AbstractIvpOdeSolver.hpp"
46#include "CvodeContextManager.hpp"
47#include "OdeSolution.hpp"
48
49// CVODE headers
50#include <cvode/cvode.h>
51#include <nvector/nvector_serial.h>
52
53#include <sunlinsol/sunlinsol_dense.h> /* access to dense SUNLinearSolver */
54#include <sunmatrix/sunmatrix_dense.h> /* access to dense SUNMatrix */
55
56#if CHASTE_SUNDIALS_VERSION >= 70000
58#define realtype sunrealtype
59#endif
60
67#if CHASTE_SUNDIALS_VERSION >= 70000
68void CvodeErrorHandler(int errorCode, const char* module, const char* function,
69 const char* message, SUNErrCode errCode, void* pData, SUNContext sunContext);
70#else
71void CvodeErrorHandler(int errorCode, const char* module, const char* function,
72 char* message, void* pData);
73#endif
74// Note: declared here since it's also used by AbstractCvodeCell.
75
80typedef struct CvodeData_
81{
83 std::vector<realtype>* pY;
86} CvodeData;
87
115{
116private:
125 template <class Archive>
126 void serialize(Archive& archive, const unsigned int version)
127 {
128 archive& boost::serialization::base_object<AbstractIvpOdeSolver>(*this);
129 archive& mRelTol;
130 archive& mAbsTol;
131 archive& mLastInternalStepSize;
132 archive& mMaxSteps;
133 archive& mCheckForRoots;
134 // All other member variables given values on each call.
135 }
136
139
140#if CHASTE_SUNDIALS_VERSION >= 60000
145 std::shared_ptr<CvodeContextManager> mpSundialsContextManager;
146#endif
147
150
152 double mRelTol;
153
155 double mAbsTol;
156
159
164 long int mMaxSteps;
165
168
171
174
177
180
184 SUNLinearSolver mpSundialsLinearSolver;
185
191 void RecordStoppingPoint(double stopTime, N_Vector yEnd);
192
193protected:
202 void SetupCvode(AbstractOdeSystem* pOdeSystem,
203 std::vector<double>& rInitialY,
204 double startTime, double maxStep);
205
209 void FreeCvodeMemory();
210
220 void CvodeError(int flag, const char* msg);
221
222public:
230 CvodeAdaptor(double relTol = 1e-4, double absTol = 1e-6);
231
237
245 void SetTolerances(double relTol = 1e-4, double absTol = 1e-6);
246
250 double GetRelativeTolerance();
251
255 double GetAbsoluteTolerance();
256
260 double GetLastStepSize();
261
269 void SetForceReset(bool autoReset);
270
278 void SetMinimalReset(bool minimalReset);
279
290 void ResetSolver();
291
305 std::vector<double>& rYValues,
306 double startTime,
307 double endTime,
308 double maxStep,
309 double timeSampling);
310
321 void Solve(AbstractOdeSystem* pOdeSystem,
322 std::vector<double>& rYValues,
323 double startTime,
324 double endTime,
325 double maxStep);
326
333
340 void SetMaxSteps(long int numSteps);
341
346 long int GetMaxSteps();
347};
348
351
352#endif // _CVODEADAPTOR_HPP_
gcov doesn't like this file...
#define CHASTE_CLASS_EXPORT(T)
double GetAbsoluteTolerance()
long int GetMaxSteps()
void CvodeError(int flag, const char *msg)
long int mMaxSteps
void SetMinimalReset(bool minimalReset)
void serialize(Archive &archive, const unsigned int version)
N_Vector mLastSolutionState
SUNLinearSolver mpSundialsLinearSolver
void SetMaxSteps(long int numSteps)
void FreeCvodeMemory()
void SetForceReset(bool autoReset)
void CheckForStoppingEvents()
CvodeData mData
OdeSolution Solve(AbstractOdeSystem *pOdeSystem, std::vector< double > &rYValues, double startTime, double endTime, double maxStep, double timeSampling)
double GetLastStepSize()
double mLastInternalStepSize
friend class boost::serialization::access
void RecordStoppingPoint(double stopTime, N_Vector yEnd)
void SetupCvode(AbstractOdeSystem *pOdeSystem, std::vector< double > &rInitialY, double startTime, double maxStep)
double mLastSolutionTime
double GetRelativeTolerance()
SUNMatrix mpSundialsDenseMatrix
void SetTolerances(double relTol=1e-4, double absTol=1e-6)
AbstractOdeSystem * pSystem
std::vector< realtype > * pY