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