Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
CombinedOdeSystemInformation.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 "CombinedOdeSystemInformation.hpp"
38
39#include <cassert>
40
41boost::shared_ptr<CombinedOdeSystemInformation> CombinedOdeSystemInformation::Instance(const std::vector<AbstractOdeSystem*>& rSubsystems)
42{
43 // Get the information for the subsystems
44 std::vector<boost::shared_ptr<const AbstractOdeSystemInformation> > info_vec;
45 info_vec.reserve(rSubsystems.size());
46 for (unsigned i=0; i<rSubsystems.size(); i++)
47 {
48 info_vec.push_back(rSubsystems[i]->GetSystemInformation());
49 }
50
51 boost::shared_ptr<CombinedOdeSystemInformation> p_inst;
52
53 // Search to see if we have an information object for this sequence of
54 // subsystems already.
55 for (unsigned i=0; i<msInstances.size(); i++)
56 {
57 if (info_vec.size() == msInstances[i].subsystemInformation.size())
58 {
59 bool equal = true;
60 for (unsigned j=0; j<info_vec.size(); j++)
61 {
62 if (msInstances[i].subsystemInformation[j] != info_vec[j])
63 {
64 equal = false;
65 break;
66 }
67 }
68 if (equal)
69 {
70 p_inst = msInstances[i].pInfoInstance;
71 break;
72 }
73 }
74 }
75
76 // Create a new object if needed
77 if (!p_inst)
78 {
79 p_inst.reset(new CombinedOdeSystemInformation(info_vec));
80 struct InstancePointers inst;
81 inst.subsystemInformation = info_vec;
82 inst.pInfoInstance = p_inst;
83 msInstances.push_back(inst);
84 }
85
86 return p_inst;
87}
88
89CombinedOdeSystemInformation::CombinedOdeSystemInformation(const std::vector<boost::shared_ptr<const AbstractOdeSystemInformation> >& rSubsystemInfo)
90{
91 // Figure out our size
92 unsigned total_system_size = 0u;
93 for (unsigned i=0; i<rSubsystemInfo.size(); i++)
94 {
95 total_system_size += rSubsystemInfo[i]->rGetStateVariableNames().size();
96 }
97 mVariableNames.reserve(total_system_size);
98 mVariableUnits.reserve(total_system_size);
99 mInitialConditions.reserve(total_system_size);
100
101 // Set up our info from the subsystems
102 for (unsigned i=0; i<rSubsystemInfo.size(); i++)
103 {
104 std::vector<double> inits = rSubsystemInfo[i]->GetInitialConditions();
105 const std::vector<std::string>& names = rSubsystemInfo[i]->rGetStateVariableNames();
106 const std::vector<std::string>& units = rSubsystemInfo[i]->rGetStateVariableUnits();
107 unsigned system_size = names.size();
108 assert(inits.size() == system_size);
109 assert(units.size() == system_size);
110
111 for (unsigned j=0; j<system_size; j++)
112 {
113 mVariableNames.push_back(names[j]);
114 mVariableUnits.push_back(units[j]);
115 mInitialConditions.push_back(inits[j]);
116 }
117 }
118
119 mInitialised = true;
120}
121
122// LCOV_EXCL_START
124{
125 // does nothing; work done in constructor
126 // but we need the method because it is pure in our base class
127}
128
130std::vector<struct CombinedOdeSystemInformation::InstancePointers> CombinedOdeSystemInformation::msInstances;
131// LCOV_EXCL_STOP
CombinedOdeSystemInformation(const std::vector< boost::shared_ptr< const AbstractOdeSystemInformation > > &rSubsystemInfo)
static std::vector< struct InstancePointers > msInstances
static boost::shared_ptr< CombinedOdeSystemInformation > Instance(const std::vector< AbstractOdeSystem * > &rSubsystems)
boost::shared_ptr< CombinedOdeSystemInformation > pInfoInstance
std::vector< boost::shared_ptr< const AbstractOdeSystemInformation > > subsystemInformation