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 
00030 
00032 template<unsigned DIM>
00033 WntConcentration<DIM>* WntConcentration<DIM>::mpInstance = NULL;
00034 
00035 
00036 template<unsigned DIM>
00037 WntConcentration<DIM>* WntConcentration<DIM>::Instance()
00038 {
00039     if (mpInstance == NULL)
00040     {
00041         mpInstance = new WntConcentration;
00042     }
00043     return mpInstance;
00044 }
00045 
00046 template<unsigned DIM>
00047 WntConcentration<DIM>::WntConcentration()
00048     : mpTissueConfig(TissueConfig::Instance()),
00049       mpTissue(NULL),
00050       mTypeSet(false),
00051       mConstantWntValueForTesting(0),
00052       mUseConstantWntValueForTesting(false)
00053 {
00054     // Make sure there's only one instance - enforces correct serialization
00055     assert(mpInstance == NULL);
00056 }
00057 
00058 
00059 template<unsigned DIM>
00060 WntConcentration<DIM>::~WntConcentration()
00061 {
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 
00076 template<unsigned DIM>
00077 double WntConcentration<DIM>::GetWntLevel(TissueCell& rCell)
00078 {
00079     if (mUseConstantWntValueForTesting)  // to test a cell and cell cycle models without a tissue
00080     {
00081         return mConstantWntValueForTesting;
00082     }
00083 
00084     assert(mpTissue!=NULL);
00085     assert(mTypeSet);
00086 
00087     double height;
00088 
00089     if (mWntType==RADIAL)
00090     {
00091         double a = TissueConfig::Instance()->GetCryptProjectionParameterA();
00092         double b = TissueConfig::Instance()->GetCryptProjectionParameterB();
00093         height = a*pow(norm_2(mpTissue->GetLocationOfCellCentre(rCell)), b);
00094     }
00095     else
00096     {
00097         height = mpTissue->GetLocationOfCellCentre(rCell)[DIM-1];
00098     }
00099     return GetWntLevel(height);
00100 }
00101 
00102 
00103 template<unsigned DIM>
00104 c_vector<double, DIM> WntConcentration<DIM>::GetWntGradient(TissueCell& rCell)
00105 {
00106     if (mUseConstantWntValueForTesting)  // to test a cell and cell cycle models without a tissue
00107     {
00108         return zero_vector<double>(DIM);
00109     }
00110     assert(mpTissue!=NULL);
00111     assert(mTypeSet);
00112 
00113     c_vector<double, DIM> location_of_cell = mpTissue->GetLocationOfCellCentre(rCell);
00114 
00115     return GetWntGradient(location_of_cell);
00116 }
00117 
00118 
00119 template<unsigned DIM>
00120 void WntConcentration<DIM>::SetTissue(AbstractTissue<DIM>& rTissue)
00121 {
00122     mpTissue = &rTissue;
00123 }
00124 
00125 
00126 template<unsigned DIM>
00127 WntConcentrationType WntConcentration<DIM>::GetType()
00128 {
00129     return mWntType;
00130 }
00131 
00132 
00133 template<unsigned DIM>
00134 void WntConcentration<DIM>::SetType(WntConcentrationType type)
00135 {
00136     if (mTypeSet==true)
00137     {
00138         EXCEPTION("Destroy has not been called");
00139     }
00140     mWntType = type;
00141     mTypeSet = true;
00142 }
00143 
00144 
00145 template<unsigned DIM>
00146 double WntConcentration<DIM>::GetWntLevel(double height)
00147 {
00148     if (mWntType==NONE)
00149     {
00150         return 0.0;
00151     }
00152 
00153     double wnt_level = -1.0; // Test this is changed before leaving method.
00154     double crypt_height = mpTissueConfig->GetCryptLength();
00155 
00156     // The first type of Wnt concentration to try
00157     if (mWntType==LINEAR || mWntType==RADIAL)
00158     {
00159         double top_of_wnt = mpTissueConfig->GetWntConcentrationParameter(); // of crypt height.
00160         if ((height >= -1e-9) && (height < top_of_wnt*crypt_height))
00161         {
00162             wnt_level = 1.0 - height/(top_of_wnt*crypt_height);
00163 
00164         }
00165         else
00166         {
00167             wnt_level = 0.0;
00168         }
00169     }
00170 
00171     if (mWntType==EXPONENTIAL)
00172     {
00173         double lambda = mpTissueConfig->GetWntConcentrationParameter(); // of crypt height.
00174         if ((height >= -1e-9) && (height < crypt_height))
00175         {
00176             wnt_level = exp(- height/(crypt_height*lambda));
00177         }
00178         else
00179         {
00180             wnt_level = 0.0;
00181         }
00182     }
00183 
00184     assert(wnt_level >= 0.0);
00185 
00186     return wnt_level;
00187 }
00188 
00189 
00190 template<unsigned DIM>
00191 c_vector<double, DIM> WntConcentration<DIM>::GetWntGradient(c_vector<double, DIM>& rLocation)
00192 {
00193     c_vector<double, DIM> wnt_gradient = zero_vector<double>(DIM);
00194 
00195     if (mWntType!=NONE)
00196     {
00197         double crypt_height = mpTissueConfig->GetCryptLength();
00198         double top_of_wnt = mpTissueConfig->GetWntConcentrationParameter(); // of crypt height.
00199 
00200         if (mWntType==LINEAR)
00201         {
00202             if ((rLocation[DIM-1] >= -1e-9) && (rLocation[DIM-1] < top_of_wnt*crypt_height))
00203             {
00204                 wnt_gradient[DIM-1] = -1.0/(top_of_wnt*crypt_height);
00205             }
00206         }
00207         else if (mWntType==RADIAL) // RADIAL Wnt concentration
00208         {
00209             double a = TissueConfig::Instance()->GetCryptProjectionParameterA();
00210             double b = TissueConfig::Instance()->GetCryptProjectionParameterB();
00211             double r = norm_2(rLocation);
00212             double r_critical = pow(top_of_wnt*crypt_height/a, 1.0/b);
00213 
00214             double dwdr = 0.0;
00215 
00216             if ( r>=-1e-9 && r<r_critical )
00217             {
00218                 dwdr = -top_of_wnt*crypt_height*pow(r, b-1.0)/a;
00219             }
00220 
00221             for (unsigned i=0; i<DIM; i++)
00222             {
00223                 wnt_gradient[i] = rLocation[i]*dwdr/r;
00224             }
00225         }
00226         else
00227         {
00228             EXCEPTION("No method to calculate gradient of this Wnt type");
00229         }
00230     }
00231     return wnt_gradient;
00232 }
00233 
00234 
00235 template<unsigned DIM>
00236 bool WntConcentration<DIM>::IsWntSetUp()
00237 {
00238     bool result = false;
00239     if (mTypeSet && mpTissue!=NULL && mWntType!=NONE)
00240     {
00241         result = true;
00242     }
00243     return result;
00244 }
00245 
00246 
00247 template<unsigned DIM>
00248 void WntConcentration<DIM>::SetConstantWntValueForTesting(double value)
00249 {
00250     if (value < 0)
00251     {
00252         EXCEPTION("WntConcentration<DIM>::SetConstantWntValueForTesting - Wnt value for testing should be non-negative.\n");
00253     }
00254     mConstantWntValueForTesting = value;
00255     mUseConstantWntValueForTesting = true;
00256     if (!mTypeSet)
00257     {
00258         mWntType = NONE;
00259     }
00260 }
00261 
00262 
00264 // Explicit instantiation
00266 
00267 template class WntConcentration<1>;
00268 template class WntConcentration<2>;
00269 template class WntConcentration<3>;

Generated by  doxygen 1.6.2