Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
BackwardEulerIvpOdeSolver.hpp
1/*
2
3Copyright (c) 2005-2024, 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 BACKWARDEULERIVPODESOLVER_HPP_
37#define BACKWARDEULERIVPODESOLVER_HPP_
38
39#include "AbstractOneStepIvpOdeSolver.hpp"
40#include "AbstractOdeSystemWithAnalyticJacobian.hpp"
41
43#include <boost/serialization/base_object.hpp>
44
45#include "AbstractOneStepIvpOdeSolver.hpp"
46
52{
53private:
62 template<class Archive>
63 void serialize(Archive & archive, const unsigned int version)
64 {
65 // This calls serialize on the base class.
66 archive & boost::serialization::base_object<AbstractOneStepIvpOdeSolver>(*this);
67 //archive & mSizeOfOdeSystem; - this done in save and load construct now.
70 }
71
74
77
83
84 /*
85 * NOTE: we use (unsafe) double pointers here rather than
86 * std::vectors because using std::vectors would lead to a
87 * slow down by a factor of about 4.
88 */
89
91 double* mResidual;
92
94 double** mJacobian;
95
97 double* mUpdate;
98
108 void ComputeResidual(AbstractOdeSystem* pAbstractOdeSystem,
109 double timeStep,
110 double time,
111 std::vector<double>& rCurrentYValues,
112 std::vector<double>& rCurrentGuess);
113
123 void ComputeJacobian(AbstractOdeSystem* pAbstractOdeSystem,
124 double timeStep,
125 double time,
126 std::vector<double>& rCurrentYValues,
127 std::vector<double>& rCurrentGuess);
128
135 void SolveLinearSystem();
136
144 double ComputeNorm(double* pVector);
145
155 void ComputeNumericalJacobian(AbstractOdeSystem* pAbstractOdeSystem,
156 double timeStep,
157 double time,
158 std::vector<double>& rCurrentYValues,
159 std::vector<double>& rCurrentGuess);
160
161protected:
162
176 void CalculateNextYValue(AbstractOdeSystem* pAbstractOdeSystem,
177 double timeStep,
178 double time,
179 std::vector<double>& rCurrentYValues,
180 std::vector<double>& rNextYValues);
181
182public:
183
189 BackwardEulerIvpOdeSolver(unsigned sizeOfOdeSystem);
190
195
202 void SetEpsilonForNumericalJacobian(double epsilon);
203
209
215 unsigned GetSystemSize() const {return mSizeOfOdeSystem;};
216};
217
220
221namespace boost
222{
223namespace serialization
224{
229template<class Archive>
230inline void save_construct_data(
231 Archive & ar, const BackwardEulerIvpOdeSolver * t, const unsigned int file_version)
232{
233 const unsigned system_size = t->GetSystemSize();
234 ar & system_size;
235}
236
243template<class Archive>
244inline void load_construct_data(
245 Archive & ar, BackwardEulerIvpOdeSolver * t, const unsigned int file_version)
246{
247 unsigned ode_system_size;
248 ar >> ode_system_size;
249 ::new(t)BackwardEulerIvpOdeSolver(ode_system_size);
250}
251}
252} // namespace ...
253
254#endif /*BACKWARDEULERIVPODESOLVER_HPP_*/
gcov doesn't like this file...
#define CHASTE_CLASS_EXPORT(T)
void ComputeNumericalJacobian(AbstractOdeSystem *pAbstractOdeSystem, double timeStep, double time, std::vector< double > &rCurrentYValues, std::vector< double > &rCurrentGuess)
void CalculateNextYValue(AbstractOdeSystem *pAbstractOdeSystem, double timeStep, double time, std::vector< double > &rCurrentYValues, std::vector< double > &rNextYValues)
void ComputeResidual(AbstractOdeSystem *pAbstractOdeSystem, double timeStep, double time, std::vector< double > &rCurrentYValues, std::vector< double > &rCurrentGuess)
void SetEpsilonForNumericalJacobian(double epsilon)
void ComputeJacobian(AbstractOdeSystem *pAbstractOdeSystem, double timeStep, double time, std::vector< double > &rCurrentYValues, std::vector< double > &rCurrentGuess)
friend class boost::serialization::access
void serialize(Archive &archive, const unsigned int version)