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