CombinedOdeSystemInformation.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
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     // Get the information for the subsystems
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     // Search to see if we have an information object for this sequence of
00047     // subsystems already.
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     // Create a new object if needed
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     // Figure out our size
00085     unsigned total_system_size = 0u;
00086     for (unsigned i=0; i<rSubsystemInfo.size(); i++)
00087     {
00088         total_system_size += rSubsystemInfo[i]->rGetVariableNames().size();
00089     }
00090     mVariableNames.reserve(total_system_size);
00091     mVariableUnits.reserve(total_system_size);
00092     mInitialConditions.reserve(total_system_size);
00093 
00094     // Set up our info from the subsystems
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]->rGetVariableNames();
00099         const std::vector<std::string>& units = rSubsystemInfo[i]->rGetVariableUnits();
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     // does nothing; work done in constructor
00119     // but we need the method because it is pure in our base class
00120 }
00121 
00123 std::vector<struct CombinedOdeSystemInformation::InstancePointers> CombinedOdeSystemInformation::msInstances;
00124 #undef COVERAGE_IGNORE

Generated by  doxygen 1.6.2