CombinedOdeSystemInformation.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "CombinedOdeSystemInformation.hpp"
00038
00039 #include <cassert>
00040
00041 boost::shared_ptr<CombinedOdeSystemInformation> CombinedOdeSystemInformation::Instance(const std::vector<AbstractOdeSystem*>& rSubsystems)
00042 {
00043
00044 std::vector<boost::shared_ptr<const AbstractOdeSystemInformation> > info_vec;
00045 info_vec.reserve(rSubsystems.size());
00046 for (unsigned i=0; i<rSubsystems.size(); i++)
00047 {
00048 info_vec.push_back(rSubsystems[i]->GetSystemInformation());
00049 }
00050
00051 boost::shared_ptr<CombinedOdeSystemInformation> p_inst;
00052
00053
00054
00055 for (unsigned i=0; i<msInstances.size(); i++)
00056 {
00057 if (info_vec.size() == msInstances[i].subsystemInformation.size())
00058 {
00059 bool equal = true;
00060 for (unsigned j=0; j<info_vec.size(); j++)
00061 {
00062 if (msInstances[i].subsystemInformation[j] != info_vec[j])
00063 {
00064 equal = false;
00065 break;
00066 }
00067 }
00068 if (equal)
00069 {
00070 p_inst = msInstances[i].pInfoInstance;
00071 break;
00072 }
00073 }
00074 }
00075
00076
00077 if (!p_inst)
00078 {
00079 p_inst.reset(new CombinedOdeSystemInformation(info_vec));
00080 struct InstancePointers inst;
00081 inst.subsystemInformation = info_vec;
00082 inst.pInfoInstance = p_inst;
00083 msInstances.push_back(inst);
00084 }
00085
00086 return p_inst;
00087 }
00088
00089 CombinedOdeSystemInformation::CombinedOdeSystemInformation(const std::vector<boost::shared_ptr<const AbstractOdeSystemInformation> >& rSubsystemInfo)
00090 {
00091
00092 unsigned total_system_size = 0u;
00093 for (unsigned i=0; i<rSubsystemInfo.size(); i++)
00094 {
00095 total_system_size += rSubsystemInfo[i]->rGetStateVariableNames().size();
00096 }
00097 mVariableNames.reserve(total_system_size);
00098 mVariableUnits.reserve(total_system_size);
00099 mInitialConditions.reserve(total_system_size);
00100
00101
00102 for (unsigned i=0; i<rSubsystemInfo.size(); i++)
00103 {
00104 std::vector<double> inits = rSubsystemInfo[i]->GetInitialConditions();
00105 const std::vector<std::string>& names = rSubsystemInfo[i]->rGetStateVariableNames();
00106 const std::vector<std::string>& units = rSubsystemInfo[i]->rGetStateVariableUnits();
00107 unsigned system_size = names.size();
00108 assert(inits.size() == system_size);
00109 assert(units.size() == system_size);
00110
00111 for (unsigned j=0; j<system_size; j++)
00112 {
00113 mVariableNames.push_back(names[j]);
00114 mVariableUnits.push_back(units[j]);
00115 mInitialConditions.push_back(inits[j]);
00116 }
00117 }
00118
00119 mInitialised = true;
00120 }
00121
00122 #define COVERAGE_IGNORE
00123 void CombinedOdeSystemInformation::Initialise()
00124 {
00125
00126
00127 }
00128
00130 std::vector<struct CombinedOdeSystemInformation::InstancePointers> CombinedOdeSystemInformation::msInstances;
00131 #undef COVERAGE_IGNORE