AbstractLookupTableCollection.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 #include "AbstractLookupTableCollection.hpp"
00030 
00031 #include <cmath>
00032 
00033 AbstractLookupTableCollection::AbstractLookupTableCollection()
00034     : mDt(0.0)
00035 {
00036 }
00037 
00038 std::vector<std::string> AbstractLookupTableCollection::GetKeyingVariableNames() const
00039 {
00040     return mKeyingVariableNames;
00041 }
00042 
00043 unsigned AbstractLookupTableCollection::GetNumberOfTables(const std::string& rKeyingVariableName) const
00044 {
00045     return mNumberOfTables[GetTableIndex(rKeyingVariableName)];
00046 }
00047 
00048 void AbstractLookupTableCollection::GetTableProperties(const std::string& rKeyingVariableName, double& rMin, double& rStep, double& rMax) const
00049 {
00050     unsigned i = GetTableIndex(rKeyingVariableName);
00051     rMin = mTableMins[i];
00052     rStep = mTableSteps[i];
00053     rMax = mTableMaxs[i];
00054 }
00055 
00056 void AbstractLookupTableCollection::SetTableProperties(const std::string& rKeyingVariableName, double min, double step, double max)
00057 {
00058     // Check inputs
00059     unsigned num_steps = (unsigned) ((max-min)/step+0.5);
00060     if (fabs(max - min - num_steps*step) > 1e-10)
00061     {
00062         EXCEPTION("Table step size does not divide range between table limits.");
00063     }
00064     // Set state
00065     unsigned i = GetTableIndex(rKeyingVariableName);
00066     if ((min != mTableMins[i]) || (step != mTableSteps[i]) || (max != mTableMaxs[i]))
00067     {
00068         mNeedsRegeneration[i] = true;
00069     }
00070     mTableMins[i] = min;
00071     mTableSteps[i] = step;
00072     mTableStepInverses[i] = 1/step;
00073     mTableMaxs[i] = max;
00074 }
00075 
00076 void AbstractLookupTableCollection::SetTimestep(double dt)
00077 {
00078     if (mDt != dt)
00079     {
00080         mNeedsRegeneration.assign(mNeedsRegeneration.size(), true);
00081     }
00082     mDt = dt;
00083 }
00084 
00085 unsigned AbstractLookupTableCollection::GetTableIndex(const std::string& rKeyingVariableName) const
00086 {
00087     unsigned i=0;
00088     for (; i<mKeyingVariableNames.size(); i++)
00089     {
00090         if (mKeyingVariableNames[i] == rKeyingVariableName)
00091         {
00092             break;
00093         }
00094     }
00095     if (i == mKeyingVariableNames.size())
00096     {
00097         EXCEPTION("Lookup table keying variable '" + rKeyingVariableName + "' does not exist.");
00098     }
00099     return i;
00100 }
00101 
00102 AbstractLookupTableCollection::~AbstractLookupTableCollection()
00103 {
00104 }
00105 
00106 const char* AbstractLookupTableCollection::EventHandler::EventName[] =  {"GenTables"};

Generated on Mon Apr 18 11:35:28 2011 for Chaste by  doxygen 1.5.5