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 WntConcentration* WntConcentration::mpInstance = NULL;
00033 
00034 
00035 WntConcentration* WntConcentration::Instance()
00036 {
00037     if (mpInstance == NULL)
00038     {
00039         mpInstance = new WntConcentration;
00040     }
00041     return mpInstance;
00042 }
00043 
00044 
00045 WntConcentration::WntConcentration()
00046  :  mpCancerParams(CancerParameters::Instance()),
00047     mpTissue(NULL),
00048     mTypeSet(false),
00049     mConstantWntValueForTesting(0),
00050     mUseConstantWntValueForTesting(false)
00051 {
00052     // Make sure there's only one instance - enforces correct serialization
00053     assert(mpInstance == NULL);
00054 }
00055 
00056 
00057 WntConcentration::~WntConcentration()
00058 {
00059 }
00060 
00061 
00062 void WntConcentration::Destroy()
00063 {
00064     if (mpInstance)
00065     {
00066         delete mpInstance;
00067         mpInstance = NULL;
00068     }
00069 }
00070 
00071 
00072 double WntConcentration::GetWntLevel(TissueCell* pCell)
00073 {
00074     if (mUseConstantWntValueForTesting)  // to test a cell and cell cycle models without a tissue
00075     {
00076         return mConstantWntValueForTesting;
00077     }
00078 
00079     assert(mpTissue!=NULL);
00080     assert(mTypeSet);
00081     assert(pCell!=NULL);
00082 
00083     double height;
00084 
00085     if (mWntType==RADIAL)
00086     {
00087         double a = CancerParameters::Instance()->GetCryptProjectionParameterA();
00088         double b = CancerParameters::Instance()->GetCryptProjectionParameterB();
00089         height = a*pow(norm_2(mpTissue->GetLocationOfCellCentre(pCell)), b);
00090     }
00091     else
00092     {
00093         height = mpTissue->GetLocationOfCellCentre(pCell)[1]; // y-coordinate
00094     }
00095     return GetWntLevel(height);
00096 }
00097 
00098 
00099 c_vector<double,2> WntConcentration::GetWntGradient(TissueCell* pCell)
00100 {
00101     if (mUseConstantWntValueForTesting)  // to test a cell and cell cycle models without a tissue
00102     {
00103         return zero_vector<double>(2);
00104     }
00105     assert(mpTissue!=NULL);
00106     assert(mTypeSet);
00107     assert(pCell!=NULL);
00108 
00109     c_vector<double,2> location_of_cell = mpTissue->GetLocationOfCellCentre(pCell);
00110 
00111     return GetWntGradient(location_of_cell);
00112 }
00113 
00114 
00115 void WntConcentration::SetTissue(AbstractTissue<2>& rTissue)
00116 {
00117     mpTissue = &rTissue;
00118 }
00119 
00120 
00121 WntConcentrationType WntConcentration::GetType()
00122 {
00123     return mWntType;
00124 }
00125 
00126 
00127 void WntConcentration::SetType(WntConcentrationType type)
00128 {
00129     if (mTypeSet==true)
00130     {
00131         EXCEPTION("Destroy has not been called");
00132     }
00133     mWntType = type;
00134     mTypeSet = true;
00135 }
00136 
00137 
00138 double WntConcentration::GetWntLevel(double height)
00139 {
00140     double wnt_level = -1.0;
00141 
00142     if (mWntType==NONE)
00143     {
00144         wnt_level=0.0;
00145     }
00146 
00147     // The first type of Wnt concentration to try
00148     if (mWntType==LINEAR || mWntType==RADIAL)
00149     {
00150         double crypt_height = mpCancerParams->GetCryptLength();
00151         double top_of_wnt = mpCancerParams->GetTopOfLinearWntConcentration(); // of crypt height.
00152 
00153         if ((height >= -1e-9) && (height < top_of_wnt*crypt_height))
00154         {
00155             wnt_level = 1.0 - height/(top_of_wnt*crypt_height);
00156         }
00157         else
00158         {
00159             wnt_level = 0.0;
00160         }
00161     }
00162 
00163     assert(wnt_level >= 0.0);
00164 
00165     return wnt_level;
00166 }
00167 
00168 
00169 c_vector<double,2> WntConcentration::GetWntGradient(c_vector<double,2> location)
00170 {
00171     c_vector<double,2> wnt_gradient = zero_vector<double>(2);
00172 
00173     if (mWntType!=NONE)
00174     {
00175         double crypt_height = mpCancerParams->GetCryptLength();
00176         double top_of_wnt = mpCancerParams->GetTopOfLinearWntConcentration(); // of crypt height.
00177 
00178         if (mWntType==LINEAR)
00179         {
00180             if ((location[1] >= -1e-9) && (location[1] < top_of_wnt*crypt_height))
00181             {
00182                 wnt_gradient[1] = -1.0/(top_of_wnt*crypt_height);
00183             }
00184         }
00185         else // RADIAL Wnt concentration
00186         {
00187             double a = CancerParameters::Instance()->GetCryptProjectionParameterA();
00188             double b = CancerParameters::Instance()->GetCryptProjectionParameterB();
00189             double r = norm_2(location);
00190             double r_critical = pow(top_of_wnt*crypt_height/a,1.0/b);
00191 
00192             double dwdr = 0.0;
00193 
00194             if ( r>=-1e-9 && r<r_critical )
00195             {
00196                 dwdr = -top_of_wnt*crypt_height*pow(r,b-1.0)/a;
00197             }
00198 
00199             wnt_gradient[0] = location[0]*dwdr/r;
00200             wnt_gradient[1] = location[1]*dwdr/r;
00201         }
00202     }
00203     return wnt_gradient;
00204 }
00205 
00206 
00207 bool WntConcentration::IsWntSetUp()
00208 {
00209     bool result = false;
00210     if (mTypeSet && mpTissue!=NULL && mWntType!=NONE)
00211     {
00212         result = true;
00213     }
00214     return result;
00215 }
00216 
00217 
00218 void WntConcentration::SetConstantWntValueForTesting(double value)
00219 {
00220     if (value < 0)
00221     {
00222         EXCEPTION("WntConcentration::SetConstantWntValueForTesting - Wnt value for testing should be non-negative.\n");
00223     }
00224     mConstantWntValueForTesting = value;
00225     mUseConstantWntValueForTesting = true;
00226     if (!mTypeSet)
00227     {
00228         mWntType = NONE;
00229     }
00230 }

Generated on Wed Mar 18 12:51:50 2009 for Chaste by  doxygen 1.5.5