Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
AbstractOdeSystemInformation.cpp
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
37#include <cassert>
38#include <algorithm>
39
40#include "AbstractOdeSystemInformation.hpp"
41#include "Exception.hpp"
42
47
51
53{
54 return mSystemName;
55}
56
61
66
67void AbstractOdeSystemInformation::SetDefaultInitialConditions(const std::vector<double>& rInitialConditions)
68{
69 assert(mInitialised);
70 mInitialConditions = rInitialConditions;
71}
72
73void AbstractOdeSystemInformation::SetDefaultInitialCondition(unsigned index, double initialCondition)
74{
75 assert(mInitialised);
76 mInitialConditions.at(index) = initialCondition;
77}
78
80{
81 assert(mInitialised);
82 return mInitialConditions;
83}
84
85const std::vector<std::string>& AbstractOdeSystemInformation::rGetStateVariableNames() const
86{
87 assert(mInitialised);
88 return mVariableNames;
89}
90
91const std::vector<std::string>& AbstractOdeSystemInformation::rGetStateVariableUnits() const
92{
93 assert(mInitialised);
94 return mVariableUnits;
95}
96
97unsigned AbstractOdeSystemInformation::GetStateVariableIndex(const std::string& rName) const
98{
99 assert(mInitialised);
100 std::vector<std::string>::const_iterator it = find(mVariableNames.begin(), mVariableNames.end(), rName);
101 if (it == mVariableNames.end())
102 {
103 EXCEPTION("No state variable named '" + rName + "'.");
104 }
105 return (unsigned)(it - mVariableNames.begin());
106}
107
108bool AbstractOdeSystemInformation::HasStateVariable(const std::string& rName) const
109{
110 assert(mInitialised);
111 std::vector<std::string>::const_iterator it = find(mVariableNames.begin(), mVariableNames.end(), rName);
112 return (it != mVariableNames.end());
113}
114
116{
117 assert(mInitialised);
118 if (index >= mVariableUnits.size())
119 {
120 EXCEPTION("The index passed in must be less than the number of state variables.");
121 }
122 return mVariableUnits[index];
123}
124
125const std::vector<std::string>& AbstractOdeSystemInformation::rGetParameterNames() const
126{
127 assert(mInitialised);
128 return mParameterNames;
129}
130
131const std::vector<std::string>& AbstractOdeSystemInformation::rGetParameterUnits() const
132{
133 assert(mInitialised);
134 return mParameterUnits;
135}
136
137unsigned AbstractOdeSystemInformation::GetParameterIndex(const std::string& rName) const
138{
139 assert(mInitialised);
140 std::vector<std::string>::const_iterator it = find(mParameterNames.begin(), mParameterNames.end(), rName);
141 if (it == mParameterNames.end())
142 {
143 EXCEPTION("No parameter named '" + rName + "'.");
144 }
145 return (unsigned)(it - mParameterNames.begin());
146}
147
148bool AbstractOdeSystemInformation::HasParameter(const std::string& rName) const
149{
150 assert(mInitialised);
151 std::vector<std::string>::const_iterator it = find(mParameterNames.begin(), mParameterNames.end(), rName);
152 return (it != mParameterNames.end());
153}
154
155std::string AbstractOdeSystemInformation::GetParameterUnits(unsigned index) const
156{
157 assert(mInitialised);
158 if (index >= mParameterUnits.size())
159 {
160 EXCEPTION("The index passed in must be less than the number of parameters.");
161 }
162 return mParameterUnits[index];
163}
164
166{
167 assert(mInitialised);
168 return mParameterUnits.size();
169}
170
171unsigned AbstractOdeSystemInformation::GetAnyVariableIndex(const std::string& rName) const
172{
173 assert(mInitialised);
174 if (HasStateVariable(rName))
175 {
176 return GetStateVariableIndex(rName);
177 }
178 else if (HasParameter(rName))
179 {
180 return mVariableNames.size() + GetParameterIndex(rName);
181 }
182 else if (HasDerivedQuantity(rName))
183 {
184 return mVariableNames.size() + mParameterNames.size() + GetDerivedQuantityIndex(rName);
185 }
186 else
187 {
188 EXCEPTION("No state variable, parameter, or derived quantity named '" + rName + "'.");
189 }
190}
191
192
193bool AbstractOdeSystemInformation::HasAnyVariable(const std::string& rName) const
194{
195 assert(mInitialised);
196 return (HasStateVariable(rName) || HasParameter(rName) || HasDerivedQuantity(rName));
197}
198
200{
201 assert(mInitialised);
202 if (index < mVariableUnits.size())
203 {
204 return mVariableUnits[index];
205 }
206 else
207 {
208 unsigned offset = mVariableUnits.size();
209 if (index - offset < mParameterUnits.size())
210 {
211 return mParameterUnits[index - offset];
212 }
213 else
214 {
215 offset += mParameterUnits.size();
216 if (index - offset < mDerivedQuantityUnits.size())
217 {
218 return mDerivedQuantityUnits[index - offset];
219 }
220 else
221 {
222 EXCEPTION("Invalid index passed to GetAnyVariableUnits.");
223 }
224 }
225 }
226}
227
228
229const std::vector<std::string>& AbstractOdeSystemInformation::rGetDerivedQuantityNames() const
230{
231 assert(mInitialised);
233}
234
235const std::vector<std::string>& AbstractOdeSystemInformation::rGetDerivedQuantityUnits() const
236{
237 assert(mInitialised);
239}
240
241unsigned AbstractOdeSystemInformation::GetDerivedQuantityIndex(const std::string& rName) const
242{
243 assert(mInitialised);
244 std::vector<std::string>::const_iterator it = find(mDerivedQuantityNames.begin(), mDerivedQuantityNames.end(), rName);
245 if (it == mDerivedQuantityNames.end())
246 {
247 EXCEPTION("No derived quantity named '" + rName + "'.");
248 }
249 return (unsigned)(it - mDerivedQuantityNames.begin());
250}
251
252bool AbstractOdeSystemInformation::HasDerivedQuantity(const std::string& rName) const
253{
254 assert(mInitialised);
255 std::vector<std::string>::const_iterator it = find(mDerivedQuantityNames.begin(), mDerivedQuantityNames.end(), rName);
256 return (it != mDerivedQuantityNames.end());
257}
258
260{
261 assert(mInitialised);
262 if (index >= mDerivedQuantityUnits.size())
263 {
264 EXCEPTION("The index passed in must be less than the number of derived quantities.");
265 }
266 return mDerivedQuantityUnits[index];
267}
268
274
276{
277 assert(mInitialised);
278 return mAttributes.size();
279}
280
281bool AbstractOdeSystemInformation::HasAttribute(const std::string& rName) const
282{
283 assert(mInitialised);
284 return (mAttributes.find(rName) != mAttributes.end());
285}
286
287double AbstractOdeSystemInformation::GetAttribute(const std::string& rName) const
288{
289 assert(mInitialised);
290 std::map<std::string, double>::const_iterator it = mAttributes.find(rName);
291 if (it == mAttributes.end())
292 {
293 EXCEPTION("No attribute '" + rName + "' found.");
294 }
295 return it->second;
296}
#define EXCEPTION(message)
const std::vector< std::string > & rGetDerivedQuantityNames() const
std::string GetDerivedQuantityUnits(unsigned index) const
unsigned GetParameterIndex(const std::string &rName) const
std::string GetParameterUnits(unsigned index) const
bool HasStateVariable(const std::string &rName) const
bool HasParameter(const std::string &rName) const
std::vector< std::string > mDerivedQuantityUnits
std::string GetAnyVariableUnits(unsigned index) const
void SetDefaultInitialConditions(const std::vector< double > &rInitialConditions)
const std::vector< std::string > & rGetStateVariableNames() const
std::vector< double > GetInitialConditions() const
const std::vector< std::string > & rGetStateVariableUnits() const
std::map< std::string, double > mAttributes
const std::vector< std::string > & rGetParameterUnits() const
double GetAttribute(const std::string &rName) const
std::vector< std::string > mDerivedQuantityNames
bool HasAnyVariable(const std::string &rName) const
const std::vector< std::string > & rGetDerivedQuantityUnits() const
const std::vector< std::string > & rGetParameterNames() const
std::string GetStateVariableUnits(unsigned index) const
unsigned GetStateVariableIndex(const std::string &rName) const
void SetDefaultInitialCondition(unsigned index, double initialCondition)
bool HasDerivedQuantity(const std::string &rName) const
unsigned GetAnyVariableIndex(const std::string &rName) const
unsigned GetDerivedQuantityIndex(const std::string &rName) const
bool HasAttribute(const std::string &rName) const