37 #include "BackwardEulerIvpOdeSolver.hpp" 43 std::vector<double>& rCurrentYValues,
44 std::vector<double>& rCurrentGuess)
50 mResidual[i] = rCurrentGuess[i] - timeStep * dy[i] - rCurrentYValues[i];
57 std::vector<double>& rCurrentYValues,
58 std::vector<double>& rCurrentGuess)
101 for (
int i=mSizeOfOdeSystem-1; i>=0; i--)
117 if (fabs(pVector[i]) > norm)
119 norm = fabs(pVector[i]);
128 std::vector<double>& rCurrentYValues,
129 std::vector<double>& rCurrentGuess)
137 ComputeResidual(pAbstractOdeSystem, timeStep, time, rCurrentYValues, rCurrentGuess);
143 for (
unsigned global_column=0; global_column<
mSizeOfOdeSystem; global_column++)
147 guess_perturbed[i] = rCurrentGuess[i];
150 guess_perturbed[global_column] += epsilon;
152 ComputeResidual(pAbstractOdeSystem, timeStep, time, rCurrentYValues, guess_perturbed);
159 double one_over_eps = 1.0/epsilon;
162 mJacobian[i][global_column] = one_over_eps*(residual_perturbed[i] - residual[i]);
170 std::vector<double>& rCurrentYValues,
171 std::vector<double>& rNextYValues)
176 unsigned counter = 0;
178 const double eps = 1e-6;
182 current_guess.assign(rCurrentYValues.begin(), rCurrentYValues.end());
187 ComputeResidual(pAbstractOdeSystem, timeStep, time, rCurrentYValues, current_guess);
188 ComputeJacobian(pAbstractOdeSystem, timeStep, time, rCurrentYValues, current_guess);
201 current_guess[i] -=
mUpdate[i];
205 assert(counter < 20);
207 rNextYValues.assign(current_guess.begin(), current_guess.end());
void SetEpsilonForNumericalJacobian(double epsilon)
unsigned mSizeOfOdeSystem
bool GetUseAnalyticJacobian()
BackwardEulerIvpOdeSolver(unsigned sizeOfOdeSystem)
virtual void EvaluateYDerivatives(double time, const std::vector< double > &rY, std::vector< double > &rDY)=0
~BackwardEulerIvpOdeSolver()
unsigned GetNumberOfStateVariables() const
void ForceUseOfNumericalJacobian()
double mNumericalJacobianEpsilon
void ComputeJacobian(AbstractOdeSystem *pAbstractOdeSystem, double timeStep, double time, std::vector< double > &rCurrentYValues, std::vector< double > &rCurrentGuess)
virtual void AnalyticJacobian(const std::vector< double > &rSolutionGuess, double **jacobian, double time, double timeStep)=0
void ComputeNumericalJacobian(AbstractOdeSystem *pAbstractOdeSystem, double timeStep, double time, std::vector< double > &rCurrentYValues, std::vector< double > &rCurrentGuess)
bool mForceUseOfNumericalJacobian
#define CHASTE_CLASS_EXPORT(T)
void ComputeResidual(AbstractOdeSystem *pAbstractOdeSystem, double timeStep, double time, std::vector< double > &rCurrentYValues, std::vector< double > &rCurrentGuess)
double ComputeNorm(double *pVector)
void CalculateNextYValue(AbstractOdeSystem *pAbstractOdeSystem, double timeStep, double time, std::vector< double > &rCurrentYValues, std::vector< double > &rNextYValues)