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);
00061     if (fabs(max - min - num_steps*step) > 1e-10)
00062     {
00063         EXCEPTION("Table step size does not divide range between table limits.");
00064     }
00065     // Set state
00066     unsigned i = GetTableIndex(rKeyingVariableName);
00067     if ((min != mTableMins[i]) || (step != mTableSteps[i]) || (max != mTableMaxs[i]))
00068     {
00069         mNeedsRegeneration[i] = true;
00070     }
00071     mTableMins[i] = min;
00072     mTableSteps[i] = step;
00073     mTableStepInverses[i] = 1/step;
00074     mTableMaxs[i] = max;
00075 }
00076 
00077 void AbstractLookupTableCollection::SetTimestep(double dt)
00078 {
00079     if (mDt != dt)
00080     {
00081         mNeedsRegeneration.assign(mNeedsRegeneration.size(), true);
00082     }
00083     mDt = dt;
00084 }
00085 
00086 unsigned AbstractLookupTableCollection::GetTableIndex(const std::string& rKeyingVariableName) const
00087 {
00088     unsigned i=0;
00089     for (; i<mKeyingVariableNames.size(); i++)
00090     {
00091         if (mKeyingVariableNames[i] == rKeyingVariableName)
00092         {
00093             break;
00094         }
00095     }
00096     if (i == mKeyingVariableNames.size())
00097     {
00098         EXCEPTION("Lookup table keying variable '" + rKeyingVariableName + "' does not exist.");
00099     }
00100     return i;
00101 }
00102 
00103 AbstractLookupTableCollection::~AbstractLookupTableCollection()
00104 {
00105 }
00106 
00107 const char* AbstractLookupTableCollection::EventHandler::EventName[] =  {"GenTables"};
Generated on Thu Dec 22 13:00:06 2011 for Chaste by  doxygen 1.6.3