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