WntConcentration.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 #include "WntConcentration.hpp"
00029 
00031 template<unsigned DIM>
00032 WntConcentration<DIM>* WntConcentration<DIM>::mpInstance = NULL;
00033 
00034 template<unsigned DIM>
00035 WntConcentration<DIM>* WntConcentration<DIM>::Instance()
00036 {
00037     if (mpInstance == NULL)
00038     {
00039         mpInstance = new WntConcentration;
00040     }
00041     return mpInstance;
00042 }
00043 
00044 template<unsigned DIM>
00045 WntConcentration<DIM>::WntConcentration()
00046     : mLengthSet(false),
00047       mpCellPopulation(NULL),
00048       mTypeSet(false),
00049       mConstantWntValueForTesting(0),
00050       mUseConstantWntValueForTesting(false),
00051       mWntConcentrationParameter(1.0),
00052       mCryptProjectionParameterA(0.5),
00053       mCryptProjectionParameterB(2.0)
00054 
00055 {
00056     // Make sure there's only one instance - enforces correct serialization
00057     assert(mpInstance == NULL);
00058 }
00059 
00060 template<unsigned DIM>
00061 WntConcentration<DIM>::~WntConcentration()
00062 {
00063 }
00064 
00065 template<unsigned DIM>
00066 void WntConcentration<DIM>::Destroy()
00067 {
00068     if (mpInstance)
00069     {
00070         delete mpInstance;
00071         mpInstance = NULL;
00072     }
00073 }
00074 
00075 template<unsigned DIM>
00076 double WntConcentration<DIM>::GetWntLevel(CellPtr pCell)
00077 {
00078     if (mUseConstantWntValueForTesting)  // to test a cell and cell cycle models without a cell population
00079     {
00080         return mConstantWntValueForTesting;
00081     }
00082 
00083     assert(mpCellPopulation!=NULL);
00084     assert(mTypeSet);
00085     assert(mLengthSet);
00086 
00087     double height;
00088 
00089     if (mWntType==RADIAL)
00090     {
00091         double a = GetCryptProjectionParameterA();
00092         double b = GetCryptProjectionParameterB();
00093         height = a*pow(norm_2(mpCellPopulation->GetLocationOfCellCentre(pCell)), b);
00094     }
00095     else
00096     {
00097         height = mpCellPopulation->GetLocationOfCellCentre(pCell)[DIM-1];
00098     }
00099 
00100     return GetWntLevel(height);
00101 }
00102 
00103 template<unsigned DIM>
00104 c_vector<double, DIM> WntConcentration<DIM>::GetWntGradient(CellPtr pCell)
00105 {
00106     if (mUseConstantWntValueForTesting)  // to test a cell and cell cycle models without a cell population
00107     {
00108         return zero_vector<double>(DIM);
00109     }
00110     assert(mpCellPopulation!=NULL);
00111     assert(mTypeSet);
00112     assert(mLengthSet);
00113 
00114     c_vector<double, DIM> location_of_cell = mpCellPopulation->GetLocationOfCellCentre(pCell);
00115 
00116     return GetWntGradient(location_of_cell);
00117 }
00118 
00119 template<unsigned DIM>
00120 void WntConcentration<DIM>::SetCellPopulation(AbstractCellPopulation<DIM>& rCellPopulation)
00121 {
00122     mpCellPopulation = &rCellPopulation;
00123 }
00124 
00125 template<unsigned DIM>
00126 double WntConcentration<DIM>::GetCryptLength()
00127 {
00128     return mCryptLength;
00129 }
00130 
00131 template<unsigned DIM>
00132 void WntConcentration<DIM>::SetCryptLength(double cryptLength)
00133 {
00134     assert(cryptLength > 0.0);
00135     if (mLengthSet==true)
00136     {
00137         EXCEPTION("Destroy has not been called");
00138     }
00139     mCryptLength = cryptLength;
00140     mLengthSet = true;
00141 }
00142 
00143 template<unsigned DIM>
00144 WntConcentrationType WntConcentration<DIM>::GetType()
00145 {
00146     return mWntType;
00147 }
00148 
00149 template<unsigned DIM>
00150 void WntConcentration<DIM>::SetType(WntConcentrationType type)
00151 {
00152     if (mTypeSet==true)
00153     {
00154         EXCEPTION("Destroy has not been called");
00155     }
00156     mWntType = type;
00157     mTypeSet = true;
00158 }
00159 
00160 template<unsigned DIM>
00161 double WntConcentration<DIM>::GetWntLevel(double height)
00162 {
00163     if (mWntType==NONE)
00164     {
00165         return 0.0;
00166     }
00167 
00168     // Need to call SetCryptLength first
00169     assert(mLengthSet);
00170 
00171     double wnt_level = -1.0; // Test this is changed before leaving method.
00172 
00173     // The first type of Wnt concentration to try
00174     if (mWntType==LINEAR || mWntType==RADIAL)
00175     {
00176         if ((height >= -1e-9) && (height < mWntConcentrationParameter*GetCryptLength()))
00177         {
00178             wnt_level = 1.0 - height/(mWntConcentrationParameter*GetCryptLength());
00179         }
00180         else
00181         {
00182             wnt_level = 0.0;
00183         }
00184     }
00185 
00186     if (mWntType==EXPONENTIAL)
00187     {
00188         if ((height >= -1e-9) && (height < GetCryptLength()))
00189         {
00190             wnt_level = exp(-height/(GetCryptLength()*mWntConcentrationParameter));
00191         }
00192         else
00193         {
00194             wnt_level = 0.0;
00195         }
00196     }
00197 
00198     assert(wnt_level >= 0.0);
00199 
00200     return wnt_level;
00201 }
00202 
00203 template<unsigned DIM>
00204 c_vector<double, DIM> WntConcentration<DIM>::GetWntGradient(c_vector<double, DIM>& rLocation)
00205 {
00206     c_vector<double, DIM> wnt_gradient = zero_vector<double>(DIM);
00207 
00208     if (mWntType!=NONE)
00209     {
00210         if (mWntType==LINEAR)
00211         {
00212             if ((rLocation[DIM-1] >= -1e-9) && (rLocation[DIM-1] < mWntConcentrationParameter*GetCryptLength()))
00213             {
00214                 wnt_gradient[DIM-1] = -1.0/(mWntConcentrationParameter*GetCryptLength());
00215             }
00216         }
00217         else if (mWntType==RADIAL) // RADIAL Wnt concentration
00218         {
00219             double a = GetCryptProjectionParameterA();
00220             double b = GetCryptProjectionParameterB();
00221             double r = norm_2(rLocation);
00222             double r_critical = pow(mWntConcentrationParameter*GetCryptLength()/a, 1.0/b);
00223 
00224             double dwdr = 0.0;
00225 
00226             if (r>=-1e-9 && r<r_critical)
00227             {
00228                 dwdr = -mWntConcentrationParameter*GetCryptLength()*pow(r, b-1.0)/a;
00229             }
00230 
00231             for (unsigned i=0; i<DIM; i++)
00232             {
00233                 wnt_gradient[i] = rLocation[i]*dwdr/r;
00234             }
00235         }
00236         else
00237         {
00238             EXCEPTION("No method to calculate gradient of this Wnt type");
00239         }
00240     }
00241     return wnt_gradient;
00242 }
00243 
00244 template<unsigned DIM>
00245 bool WntConcentration<DIM>::IsWntSetUp()
00246 {
00247     bool result = false;
00248     if (mTypeSet && mLengthSet && mpCellPopulation!=NULL && mWntType!=NONE)
00249     {
00250         result = true;
00251     }
00252     return result;
00253 }
00254 
00255 template<unsigned DIM>
00256 void WntConcentration<DIM>::SetConstantWntValueForTesting(double value)
00257 {
00258     if (value < 0)
00259     {
00260         EXCEPTION("WntConcentration<DIM>::SetConstantWntValueForTesting - Wnt value for testing should be non-negative.\n");
00261     }
00262     mConstantWntValueForTesting = value;
00263     mUseConstantWntValueForTesting = true;
00264     if (!mTypeSet)
00265     {
00266         mWntType = NONE;
00267     }
00268 }
00269 
00270 template<unsigned DIM>
00271 double WntConcentration<DIM>::GetWntConcentrationParameter()
00272 {
00273     return mWntConcentrationParameter;
00274 }
00275 
00276 template<unsigned DIM>
00277 void WntConcentration<DIM>::SetWntConcentrationParameter(double wntConcentrationParameter)
00278 {
00279     assert(wntConcentrationParameter > 0.0);
00280     mWntConcentrationParameter = wntConcentrationParameter;
00281 }
00282 
00283 template<unsigned DIM>
00284 double WntConcentration<DIM>::GetCryptProjectionParameterA()
00285 {
00286     return mCryptProjectionParameterA;
00287 }
00288 
00289 template<unsigned DIM>
00290 double WntConcentration<DIM>::GetCryptProjectionParameterB()
00291 {
00292     return mCryptProjectionParameterB;
00293 }
00294 
00295 template<unsigned DIM>
00296 void WntConcentration<DIM>::SetCryptProjectionParameterA(double cryptProjectionParameterA)
00297 {
00298     assert(cryptProjectionParameterA >= 0.0);
00299     mCryptProjectionParameterA = cryptProjectionParameterA;
00300 }
00301 
00302 template<unsigned DIM>
00303 void WntConcentration<DIM>::SetCryptProjectionParameterB(double cryptProjectionParameterB)
00304 {
00305     assert(cryptProjectionParameterB >= 0.0);
00306     mCryptProjectionParameterB = cryptProjectionParameterB;
00307 }
00308 
00310 // Explicit instantiation
00312 
00313 template class WntConcentration<1>;
00314 template class WntConcentration<2>;
00315 template class WntConcentration<3>;

Generated on Mon Nov 1 12:35:16 2010 for Chaste by  doxygen 1.5.5