WntConcentration.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
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* pCell)
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     assert(pCell!=NULL);
00087 
00088     double height;
00089 
00090     if (mWntType==RADIAL)
00091     {
00092         double a = TissueConfig::Instance()->GetCryptProjectionParameterA();
00093         double b = TissueConfig::Instance()->GetCryptProjectionParameterB();
00094         height = a*pow(norm_2(mpTissue->GetLocationOfCellCentre(pCell)), b);
00095     }
00096     else
00097     {
00098         height = mpTissue->GetLocationOfCellCentre(pCell)[DIM-1];
00099     }
00100     return GetWntLevel(height);
00101 }
00102 
00103 
00104 template<unsigned DIM>
00105 c_vector<double, DIM> WntConcentration<DIM>::GetWntGradient(TissueCell* pCell)
00106 {
00107     if (mUseConstantWntValueForTesting)  // to test a cell and cell cycle models without a tissue
00108     {
00109         return zero_vector<double>(DIM);
00110     }
00111     assert(mpTissue!=NULL);
00112     assert(mTypeSet);
00113     assert(pCell!=NULL);
00114 
00115     c_vector<double, DIM> location_of_cell = mpTissue->GetLocationOfCellCentre(pCell);
00116 
00117     return GetWntGradient(location_of_cell);
00118 }
00119 
00120 
00121 template<unsigned DIM>
00122 void WntConcentration<DIM>::SetTissue(AbstractTissue<DIM>& rTissue)
00123 {
00124     mpTissue = &rTissue;
00125 }
00126 
00127 
00128 template<unsigned DIM>
00129 WntConcentrationType WntConcentration<DIM>::GetType()
00130 {
00131     return mWntType;
00132 }
00133 
00134 
00135 template<unsigned DIM>
00136 void WntConcentration<DIM>::SetType(WntConcentrationType type)
00137 {
00138     if (mTypeSet==true)
00139     {
00140         EXCEPTION("Destroy has not been called");
00141     }
00142     mWntType = type;
00143     mTypeSet = true;
00144 }
00145 
00146 
00147 template<unsigned DIM>
00148 double WntConcentration<DIM>::GetWntLevel(double height)
00149 {
00150     double wnt_level = -1.0;
00151 
00152     if (mWntType==NONE)
00153     {
00154         wnt_level = 0.0;
00155     }
00156 
00157     // The first type of Wnt concentration to try
00158     if (mWntType==LINEAR || mWntType==RADIAL)
00159     {
00160         double crypt_height = mpTissueConfig->GetCryptLength();
00161         double top_of_wnt = mpTissueConfig->GetTopOfLinearWntConcentration(); // of crypt height.
00162 
00163         if ((height >= -1e-9) && (height < top_of_wnt*crypt_height))
00164         {
00165             wnt_level = 1.0 - height/(top_of_wnt*crypt_height);
00166         }
00167         else
00168         {
00169             wnt_level = 0.0;
00170         }
00171     }
00172 
00173     assert(wnt_level >= 0.0);
00174 
00175     return wnt_level;
00176 }
00177 
00178 
00179 template<unsigned DIM>
00180 c_vector<double, DIM> WntConcentration<DIM>::GetWntGradient(c_vector<double, DIM> location)
00181 {
00182     c_vector<double, DIM> wnt_gradient = zero_vector<double>(DIM);
00183 
00184     if (mWntType!=NONE)
00185     {
00186         double crypt_height = mpTissueConfig->GetCryptLength();
00187         double top_of_wnt = mpTissueConfig->GetTopOfLinearWntConcentration(); // of crypt height.
00188 
00189         if (mWntType==LINEAR)
00190         {
00191             if ((location[DIM-1] >= -1e-9) && (location[DIM-1] < top_of_wnt*crypt_height))
00192             {
00193                 wnt_gradient[DIM-1] = -1.0/(top_of_wnt*crypt_height);
00194             }
00195         }
00196         else // RADIAL Wnt concentration
00197         {
00198             double a = TissueConfig::Instance()->GetCryptProjectionParameterA();
00199             double b = TissueConfig::Instance()->GetCryptProjectionParameterB();
00200             double r = norm_2(location);
00201             double r_critical = pow(top_of_wnt*crypt_height/a, 1.0/b);
00202 
00203             double dwdr = 0.0;
00204 
00205             if ( r>=-1e-9 && r<r_critical )
00206             {
00207                 dwdr = -top_of_wnt*crypt_height*pow(r, b-1.0)/a;
00208             }
00209 
00210             for (unsigned i=0; i<DIM; i++)
00211             {
00212                 wnt_gradient[i] = location[i]*dwdr/r;
00213             }
00214         }
00215     }
00216     return wnt_gradient;
00217 }
00218 
00219 
00220 template<unsigned DIM>
00221 bool WntConcentration<DIM>::IsWntSetUp()
00222 {
00223     bool result = false;
00224     if (mTypeSet && mpTissue!=NULL && mWntType!=NONE)
00225     {
00226         result = true;
00227     }
00228     return result;
00229 }
00230 
00231 
00232 template<unsigned DIM>
00233 void WntConcentration<DIM>::SetConstantWntValueForTesting(double value)
00234 {
00235     if (value < 0)
00236     {
00237         EXCEPTION("WntConcentration<DIM>::SetConstantWntValueForTesting - Wnt value for testing should be non-negative.\n");
00238     }
00239     mConstantWntValueForTesting = value;
00240     mUseConstantWntValueForTesting = true;
00241     if (!mTypeSet)
00242     {
00243         mWntType = NONE;
00244     }
00245 }
00246 
00247 
00249 // Explicit instantiation
00251 
00252 template class WntConcentration<1>;
00253 template class WntConcentration<2>;
00254 template class WntConcentration<3>;

Generated on Tue Aug 4 16:10:21 2009 for Chaste by  doxygen 1.5.5