LifeV
lifev/electrophysiology/testsuite/test_0DGoldbeterModel/main.cpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief 0D test with the Goldbeter model for simplified Calcium dynamics
30 
31  @date 04 - 2014
32  @author Simone Rossi <simone.rossi@epfl.ch>
33 
34  @contributor
35  @mantainer Simone Rossi <simone.rossi@epfl.ch>
36  */
37 
38 // To save the solution
39 #include <fstream>
40 
41 // To solve the model
42 #include <lifev/electrophysiology/solver/IonicModels/IonicGoldbeter.hpp>
43 
44 // To use LifeV
45 #include <lifev/core/LifeV.hpp>
46 
47 
48 using namespace LifeV;
49 
50 //This is the norm of the precomputed solution
51 //we check the test against this value
52 #define SolutionTestNorm 639.4563875712343588
53 
55 {
56 
57  //********************************************//
58  // Creates a new model object representing the//
59  // model from Goldebeter model. //
60  //********************************************//
61  std::cout << "Building Constructor for Goldbeter Model with parameters ... ";
62  IonicGoldbeter model;
63  std::cout << " Done!" << std::endl;
64 
65 
66  //********************************************//
67  // Show the parameters of the model as well as//
68  // other informations about the object. //
69  //********************************************//
70  model.showMe();
71 
72 
73  //********************************************//
74  // Initialize the solution to 0. The model //
75  // consist of three state variables. //
76  // The method model.Size() //
77  // returns the number of state variables of //
78  // the model. rStates is the reference to the //
79  // the vector states //
80  //********************************************//
81  std::cout << "Initializing solution vector...";
82  std::vector<Real> unknowns (model.Size(), 0);
83  model.initialize (unknowns);
84  std::cout << " Done!" << std::endl;
85 
86  //********************************************//
87  // Initialize the rhs to 0. The rhs is the //
88  // vector containing the numerical values of //
89  // the time derivatives of the state //
90  // variables, that is, the right hand side of //
91  // the differential equation. //
92  //********************************************//
93  std::cout << "Initializing rhs..." ;
94  std::vector<Real> rhs (model.Size(), 0);
95  std::cout << " Done! " << std::endl;
96 
97  //********************************************//
98  // Simulation starts on t=0 and ends on t=TF. //
99  // The timestep is given by dt //
100  //********************************************//
101  Real TF (10);
102  Real dt (0.01);
103 
104  //********************************************//
105  // Open the file "output.txt" to save the //
106  // solution. //
107  //********************************************//
108  std::string filename = "output.txt";
109  std::ofstream output ("output.txt");
110 
111  //********************************************//
112  // We record the norm of the solution to //
113  // check the failure of the test //
114  //********************************************//
115  Real SolutionNorm = unknowns[0];
116 
117  //********************************************//
118  // Time loop starts. //
119  //********************************************//
120  std::cout << "Time loop starts...\n";
121  for ( Real t = 0; t < TF; )
122  {
123 
124  //********************************************//
125  // Compute the rhs using the model equations //
126  //********************************************//
127  model.computeRhs ( unknowns, rhs);
128 
129  //********************************************//
130  // Use forward Euler method to advance the //
131  // solution in time. //
132  //********************************************//
133  unknowns.at (0) = unknowns.at (0) + dt * rhs.at (0);
134  unknowns.at (1) = unknowns.at (1) + dt * rhs.at (1);
135 
136  //********************************************//
137  // Writes solution on file. //
138  //********************************************//
139  output << t << ", " << unknowns.at (0) << ", " << unknowns.at (1) << "\n";
140 
141  //********************************************//
142  // Update the time. //
143  //********************************************//
144  t = t + dt;
145 
146  //********************************************//
147  // Update the norm of the solution to check //
148  // test failure //
149  //********************************************//
150  SolutionNorm += unknowns[0];
151  }
152  std::cout << "\n...Time loop ends.\n";
153  std::cout << "Solution written on file: " << filename << "\n";
154  //********************************************//
155  // Close exported file. //
156  //********************************************//
157  output.close();
158 
159  Real returnValue;
160  Real err = std::abs (SolutionTestNorm - SolutionNorm) / std::abs (SolutionTestNorm);
161  std::cout << std::setprecision (20) << "\nError: " << err << "\nSolution norm: " << SolutionNorm << "\n";
162  if ( err > 1e-12 )
163  {
164  returnValue = EXIT_FAILURE; // Norm of solution did not match
165  }
166  else
167  {
168  returnValue = EXIT_SUCCESS;
169  }
170  return ( returnValue );
171 }
172 
173 #undef SolutionTestNorm
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
void updateInverseJacobian(const UInt &iQuadPt)
double Real
Generic real data.
Definition: LifeV.hpp:175
void showMe()
Display information about the model.