CombinedOdeSystem.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 "CombinedOdeSystem.hpp"
00038 #include "CombinedOdeSystemInformation.hpp"
00039
00040
00041
00042 CombinedOdeSystem::CombinedOdeSystem(std::vector<AbstractOdeSystem*> odeSystems)
00043 : AbstractOdeSystem(0)
00044 {
00045 mOdeSystems = odeSystems;
00046 for (unsigned i=0; i<odeSystems.size(); i++)
00047 {
00048 mNumberOfStateVariables += odeSystems[i]->GetNumberOfStateVariables();
00049 }
00050 mpSystemInfo = CombinedOdeSystemInformation::Instance(odeSystems);
00051 ResetToInitialConditions();
00052
00053
00054 unsigned num_systems = odeSystems.size();
00055 mWorkingStateVars.resize(num_systems);
00056 mWorkingDerivs.resize(num_systems);
00057 unsigned offset = 0;
00058 for (unsigned i=0; i<num_systems; i++)
00059 {
00060 unsigned num_vars = odeSystems[i]->GetNumberOfStateVariables();
00061 mWorkingStateVars[i].resize(num_vars);
00062 mWorkingDerivs[i].resize(num_vars);
00063 mOffsets.push_back(offset);
00064 offset += num_vars;
00065 }
00066 }
00067
00068
00069 void CombinedOdeSystem::Configure(
00070 const std::map<unsigned, unsigned>& rVariableParameterMap,
00071 AbstractOdeSystem* pVariableOdeSystem,
00072 AbstractOdeSystem* pParameterOdeSystem)
00073 {
00074 struct VariableParameterMap new_map;
00075 new_map.theMap = rVariableParameterMap;
00076 unsigned var_system_index = 0;
00077 while (var_system_index < mOdeSystems.size() && mOdeSystems[var_system_index] != pVariableOdeSystem)
00078 {
00079 ++var_system_index;
00080 }
00081 new_map.pVariableOdeSystemIndex = var_system_index;
00082 new_map.pParameterOdeSystem = pParameterOdeSystem;
00083 mVariableParameterMaps.push_back(new_map);
00084 }
00085
00086
00087 void CombinedOdeSystem::EvaluateYDerivatives(
00088 double time,
00089 const std::vector<double>& rY,
00090 std::vector<double>& rDY)
00091 {
00092
00093 for (unsigned i=0; i<mOdeSystems.size(); i++)
00094 {
00095 unsigned offset = mOffsets[i];
00096 for (unsigned j=0; j<mOdeSystems[i]->GetNumberOfStateVariables(); j++)
00097 {
00098 mWorkingStateVars[i][j] = rY[offset + j];
00099 }
00100 }
00101
00102
00103 for (unsigned i=0; i<mVariableParameterMaps.size(); i++)
00104 {
00105 std::map<unsigned, unsigned>& r_var_param_map = mVariableParameterMaps[i].theMap;
00106
00107 for (std::map<unsigned, unsigned>::iterator iter = r_var_param_map.begin();
00108 iter != r_var_param_map.end();
00109 ++iter)
00110 {
00111 double value = mWorkingStateVars[mVariableParameterMaps[i].pVariableOdeSystemIndex][iter->first];
00112 mVariableParameterMaps[i].pParameterOdeSystem->SetParameter(iter->second, value);
00113 }
00114 }
00115
00116
00117 for (unsigned i=0; i<mOdeSystems.size(); i++)
00118 {
00119 mOdeSystems[i]->EvaluateYDerivatives(time, mWorkingStateVars[i], mWorkingDerivs[i]);
00120 }
00121
00122
00123 for (unsigned i=0; i<mOdeSystems.size(); i++)
00124 {
00125 unsigned offset = mOffsets[i];
00126 for (unsigned j=0; j<mOdeSystems[i]->GetNumberOfStateVariables(); j++)
00127 {
00128 rDY[offset + j] = mWorkingDerivs[i][j];
00129 }
00130 }
00131 }