WntConcentration.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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)
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)
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;
00154 double crypt_height = mpTissueConfig->GetCryptLength();
00155
00156
00157 if (mWntType==LINEAR || mWntType==RADIAL)
00158 {
00159 double top_of_wnt = mpTissueConfig->GetWntConcentrationParameter();
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();
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();
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)
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
00266
00267 template class WntConcentration<1>;
00268 template class WntConcentration<2>;
00269 template class WntConcentration<3>;