Chaste  Release::2017.1
CombinedOdeSystemInformation.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 
37 #include "CombinedOdeSystemInformation.hpp"
38 
39 #include <cassert>
40 
41 boost::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 
89 CombinedOdeSystemInformation::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 
130 std::vector<struct CombinedOdeSystemInformation::InstancePointers> CombinedOdeSystemInformation::msInstances;
131 // LCOV_EXCL_STOP
std::vector< boost::shared_ptr< const AbstractOdeSystemInformation > > subsystemInformation
boost::shared_ptr< CombinedOdeSystemInformation > pInfoInstance
static std::vector< struct InstancePointers > msInstances
std::vector< std::string > mVariableNames
std::vector< std::string > mVariableUnits
static boost::shared_ptr< CombinedOdeSystemInformation > Instance(const std::vector< AbstractOdeSystem * > &rSubsystems)
CombinedOdeSystemInformation(const std::vector< boost::shared_ptr< const AbstractOdeSystemInformation > > &rSubsystemInfo)