Chaste  Release::2017.1
OdeSolution.hpp
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 
37 #ifndef _ODESOLUTION_HPP_
38 #define _ODESOLUTION_HPP_
39 
40 #include <vector>
41 #include <string>
42 #include <cassert>
43 #include <boost/shared_ptr.hpp>
44 
45 #include "AbstractOdeSystemInformation.hpp"
46 #include "AbstractParameterisedSystem.hpp"
47 
48 #ifdef CHASTE_CVODE
49 // CVODE headers
50 #include <nvector/nvector_serial.h>
51 #endif // CHASTE_CVODE
52 
53 class AbstractOdeSystem; // Avoid cyclic include issues
54 
59 {
60 private:
63 
65  std::vector<double> mTimes;
66 
68  std::vector<std::vector<double> > mSolutions;
69 
71  std::vector<std::vector<double> > mDerivedQuantities;
72 
74  std::vector<double> mParameters;
75 
77  std::string mSolverName;
78 
84  boost::shared_ptr<const AbstractOdeSystemInformation> mpOdeSystemInformation;
85 
86 public:
90  OdeSolution();
91 
97  unsigned GetNumberOfTimeSteps() const;
98 
104  void SetNumberOfTimeSteps(unsigned numTimeSteps);
105 
111  void SetOdeSystemInformation(boost::shared_ptr<const AbstractOdeSystemInformation> pOdeSystemInfo);
112 
121  std::vector<double> GetVariableAtIndex(unsigned index) const;
122 
129  std::vector<double> GetAnyVariable(const std::string& rName) const;
130 
136  std::vector<double>& rGetTimes();
137 
143  const std::vector<double>& rGetTimes() const;
144 
150  std::vector<std::vector<double> >& rGetSolutions();
151 
157  const std::vector<std::vector<double> >& rGetSolutions() const;
158 
159 
163  void SetSolverName(std::string solverName)
164  {
165  mSolverName = solverName;
166  }
167 
169  std::string GetSolverName()
170  {
171  return mSolverName;
172  }
173 
179  template<typename VECTOR>
181 
188  std::vector<std::vector<double> >& rGetDerivedQuantities(AbstractParameterisedSystem<std::vector<double> >* pOdeSystem);
189 
190 #ifdef CHASTE_CVODE
191 
197  std::vector<std::vector<double> >& rGetDerivedQuantities(AbstractParameterisedSystem<N_Vector>* pOdeSystem);
198 #endif //CHASTE_CVODE
199 
207  template<typename VECTOR>
208  std::vector<double>& rGetParameters(AbstractParameterisedSystem<VECTOR>* pOdeSystem);
209 
224  void WriteToFile(std::string directoryName,
225  std::string baseResultsFilename,
226  std::string timeUnits,
227  unsigned stepsPerRow=1,
228  bool cleanDirectory=true,
229  unsigned precision=8,
230  bool includeDerivedQuantities=false);
231 };
232 
233 
234 #endif //_ODESOLUTION_HPP_
boost::shared_ptr< const AbstractOdeSystemInformation > mpOdeSystemInformation
Definition: OdeSolution.hpp:84
unsigned mNumberOfTimeSteps
Definition: OdeSolution.hpp:62
unsigned GetNumberOfTimeSteps() const
Definition: OdeSolution.cpp:52
std::vector< std::vector< double > > & rGetSolutions()
std::vector< std::vector< double > > & rGetDerivedQuantities(AbstractParameterisedSystem< std::vector< double > > *pOdeSystem)
std::vector< std::vector< double > > mDerivedQuantities
Definition: OdeSolution.hpp:71
std::vector< double > mParameters
Definition: OdeSolution.hpp:74
std::vector< double > & rGetParameters(AbstractParameterisedSystem< VECTOR > *pOdeSystem)
void SetOdeSystemInformation(boost::shared_ptr< const AbstractOdeSystemInformation > pOdeSystemInfo)
Definition: OdeSolution.cpp:66
std::vector< double > GetVariableAtIndex(unsigned index) const
Definition: OdeSolution.cpp:71
std::string mSolverName
Definition: OdeSolution.hpp:77
std::string GetSolverName()
void WriteToFile(std::string directoryName, std::string baseResultsFilename, std::string timeUnits, unsigned stepsPerRow=1, bool cleanDirectory=true, unsigned precision=8, bool includeDerivedQuantities=false)
void CalculateDerivedQuantitiesAndParameters(AbstractParameterisedSystem< VECTOR > *pOdeSystem)
std::vector< std::vector< double > > mSolutions
Definition: OdeSolution.hpp:68
std::vector< double > & rGetTimes()
std::vector< double > mTimes
Definition: OdeSolution.hpp:65
std::vector< double > GetAnyVariable(const std::string &rName) const
void SetSolverName(std::string solverName)
void SetNumberOfTimeSteps(unsigned numTimeSteps)
Definition: OdeSolution.cpp:58