Chaste  Release::2017.1
RKC21IvpOdeSolver.cpp
1 /*
2 
3 Copyright (c) 2005-2017, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, 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 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 
45 #include "RKC21IvpOdeSolver.hpp"
46 
48  double timeStep,
49  double time,
50  std::vector<double>& rCurrentYValues,
51  std::vector<double>& rNextYValues)
52 {
53  /*
54  * Apply Runge-Kutta-Chebyshev 1st order 2 stages method for each timestep in AbstractOneStepIvpSolver.
55  * Calculates a vector containing the next Y value from the current one for each
56  * equation in the system.
57  */
58 
59 
60  /*
61  * The General RKC scheme:
62 
63  * w_{n0} = w_n;
64  * w_{n1} = w_n + \tilde{\mu_1} * dt * F_{n0};
65  * w_{nj} = (1 - mu_j - nu_j) w_n + mu_j*w_{n,j-1} + nu_j*w_{n,j-2} + \tilde{\mu_j}*dt*F_{n,j-1} + \tilde{\gamma_j}*dt*F_{n,0},
66  * w_{n+1} = w_{ns}.
67  * where:
68  * j = 2,...,s;
69  * F_{nk} = F(t_n + c_k*dt, w_{nk});
70  * c_k = T_s(w_0)*Tp_k(w_0) / (Tp_s(w_0)*T_k(w_0)) with T_k/Tp_k are k-th Chebyshev polynomials/ derivatives of them
71  * w_0 is specific parameters
72  * In RKC21, c_2 = \tilde{\mu_1}
73 
74 
75  A decent reference on this method refer to Hundsdorfer, Willem, and Jan G. Verwer. Numerical solution of time-dependent advection-diffusion-reaction equations. Vol. 33. Springer Science & Business Media, 2013. P429
76  */
77 
78  //RKC coefficients, hard-coded //TODO how to compute/where to store arbitrary RKC coefficients?
79 
80  const double mu1_tilde = 0.256134735558604;
81  const double mu2 = 1.952097590002976;
82  //const double nu2 = -b2/b0; canceled out in equation
83  const double mu2_tilde =0.500000000000000;
84  //const double gamma2_tilde = 0; never used in first order RKC
85 
86  const unsigned num_equations = pAbstractOdeSystem->GetNumberOfStateVariables();
87 
88  std::vector<double>& w0 = rCurrentYValues; // alias
89  std::vector<double> w1(num_equations);
90  std::vector<double>& w2 = rNextYValues; // alias
91  std::vector<double> F0(num_equations);
92  std::vector<double>& F1 = rNextYValues;
93 
94  // Work out w1
95  pAbstractOdeSystem->EvaluateYDerivatives(time, w0, F0);
96 
97  for (unsigned i=0; i<num_equations; i++)
98  {
99  w1[i] = w0[i] + mu1_tilde * timeStep * F0[i];
100  }
101 
102  // Work next step
103  pAbstractOdeSystem->EvaluateYDerivatives(time + mu1_tilde * timeStep, w1, F1);
104  for (unsigned i=0; i<num_equations; i++)
105  {
106  w2[i] = (1-mu2) * w0[i] + mu2 * w1[i] + mu2_tilde * timeStep * F1[i];// + gamma2_tilde*timeStep*F0[i]; -> never used
107  }
108 }
109 
110 
111 // Serialization for Boost >= 1.36
void CalculateNextYValue(AbstractOdeSystem *pAbstractOdeSystem, double timeStep, double time, std::vector< double > &rCurrentYValues, std::vector< double > &rNextYValues)
virtual void EvaluateYDerivatives(double time, const std::vector< double > &rY, std::vector< double > &rDY)=0
#define CHASTE_CLASS_EXPORT(T)