Chaste  Build::
AbstractDiscreteContinuumLinearEllipticPde.cpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4  All rights reserved.
5 
6  University of Oxford means the Chancellor, Masters and Scholars of the
7  University of Oxford, having an administrative office at Wellington
8  Square, Oxford OX1 2JD, UK.
9 
10  This file is part of Chaste.
11 
12  Redistribution and use in source and binary forms, with or without
13  modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the abovea copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34  */
35 
36 #include <algorithm>
37 #include "AbstractDiscreteContinuumLinearEllipticPde.hpp"
38 #include "BaseUnits.hpp"
39 
40 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
42  AbstractLinearEllipticPde<ELEMENT_DIM, ELEMENT_DIM>(),
43  mDiffusionTensor(identity_matrix<double>(SPACE_DIM)),
44  mDiffusivity(1.0 * unit::metre_squared_per_second),
45  mConstantInUTerm(0.0 * unit::mole_per_metre_cubed_per_second),
46  mDiscreteSources(),
47  mpRegularGrid(),
48  mpMesh(),
49  mUseRegularGrid(true),
50  mDiscreteConstantSourceStrengths(),
51  mReferenceConcentration(BaseUnits::Instance()->GetReferenceConcentrationScale())
52 {
53  mDiffusionTensor *= mDiffusivity.value();
54 }
55 
56 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
58 {
59 }
60 
61 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
63 {
64  mDiscreteSources.push_back(pDiscreteSource);
65 }
66 
67 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
69  Element<ELEMENT_DIM, SPACE_DIM>* pElement)
70 {
72  {
73  if(pElement->GetIndex() >= mDiscreteConstantSourceStrengths.size())
74  {
75  EXCEPTION("Requested out of bound grid index in discrete sources. Maybe you forgot to update the source strengths.");
76  }
77  units::quantity<unit::concentration_flow_rate> scaling_factor = mReferenceConcentration/BaseUnits::Instance()->GetReferenceTimeScale();
78  return (mConstantInUTerm + mDiscreteConstantSourceStrengths[pElement->GetIndex()]) / scaling_factor;
79  }
80  else
81  {
82  units::quantity<unit::concentration_flow_rate> scaling_factor = mReferenceConcentration/BaseUnits::Instance()->GetReferenceTimeScale();
83  return mConstantInUTerm/scaling_factor;
84  }
85 }
86 
87 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
88 units::quantity<unit::concentration_flow_rate> AbstractDiscreteContinuumLinearEllipticPde<ELEMENT_DIM, SPACE_DIM>::ComputeConstantInUSourceTerm(unsigned gridIndex)
89 {
91  {
92  if(gridIndex >= mDiscreteConstantSourceStrengths.size())
93  {
94  EXCEPTION("Requested out of bound grid index in discrete sources. Maybe you forgot to update the source strengths.");
95  }
97  }
98  else
99  {
100  return mConstantInUTerm;
101  }
102 }
103 
104 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
105 c_matrix<double, SPACE_DIM, SPACE_DIM> AbstractDiscreteContinuumLinearEllipticPde<ELEMENT_DIM, SPACE_DIM>::ComputeDiffusionTerm(const ChastePoint<SPACE_DIM>&)
106 {
107  return mDiffusionTensor;
108 }
109 
110 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
112 {
113  return mDiffusivity;
114 }
115 
116 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
117 std::vector<boost::shared_ptr<DiscreteSource<SPACE_DIM> > > AbstractDiscreteContinuumLinearEllipticPde<ELEMENT_DIM, SPACE_DIM>::GetDiscreteSources()
118 {
119  return mDiscreteSources;
120 }
121 
122 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
123 void AbstractDiscreteContinuumLinearEllipticPde<ELEMENT_DIM, SPACE_DIM>::SetContinuumConstantInUTerm(units::quantity<unit::concentration_flow_rate> constantInUTerm)
124 {
125  mConstantInUTerm = constantInUTerm;
126 }
127 
128 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
130 {
131  mDiffusivity = diffusivity;
133  mDiffusionTensor = identity_matrix<double>(SPACE_DIM)*(mDiffusivity/scaling_factor);
134 }
135 
136 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
138 {
139  mpRegularGrid = pRegularGrid;
140 }
141 
142 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
144 {
145  mpMesh = pMesh;
146 }
147 
148 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
150 {
151  mUseRegularGrid = useRegularGrid;
152 }
153 
154 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
155 void AbstractDiscreteContinuumLinearEllipticPde<ELEMENT_DIM, SPACE_DIM>::SetReferenceConcentration(units::quantity<unit::concentration> referenceConcentration)
156 {
157  mReferenceConcentration = referenceConcentration;
158 }
159 
160 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
162 {
163  if(mUseRegularGrid)
164  {
165  if(!mpRegularGrid)
166  {
167  EXCEPTION("A grid has not been set for the determination of source strengths.");
168  }
169  mDiscreteConstantSourceStrengths = std::vector<units::quantity<unit::concentration_flow_rate> >(mpRegularGrid->GetNumberOfPoints(), 0.0*unit::mole_per_metre_cubed_per_second);
170  for(unsigned idx=0; idx<mDiscreteSources.size(); idx++)
171  {
172  mDiscreteSources[idx]->SetRegularGrid(mpRegularGrid);
173  std::vector<units::quantity<unit::concentration_flow_rate> > result = mDiscreteSources[idx]->GetConstantInURegularGridValues();
175  result.begin( ), mDiscreteConstantSourceStrengths.begin( ),std::plus<units::quantity<unit::concentration_flow_rate> >( ));
176  }
177  }
178  else
179  {
180  if(!mpMesh)
181  {
182  EXCEPTION("A mesh has not been set for the determination of source strengths.");
183  }
184 
185  mDiscreteConstantSourceStrengths = std::vector<units::quantity<unit::concentration_flow_rate> >(mpMesh->GetNumElements(), 0.0*unit::mole_per_metre_cubed_per_second);
186  for(unsigned idx=0; idx<mDiscreteSources.size(); idx++)
187  {
188  mDiscreteSources[idx]->SetMesh(mpMesh);
189  std::vector<units::quantity<unit::concentration_flow_rate> > result = mDiscreteSources[idx]->GetConstantInUMeshValues();
191  result.begin( ), mDiscreteConstantSourceStrengths.begin( ),std::plus<units::quantity<unit::concentration_flow_rate> >( ));
192  }
193  }
194 }
195 
196 // Explicit instantiation
boost::shared_ptr< RegularGrid< SPACE_DIM > > mpRegularGrid
units::quantity< unit::concentration_flow_rate > mConstantInUTerm
void SetMesh(boost::shared_ptr< DiscreteContinuumMesh< ELEMENT_DIM, SPACE_DIM > > pMesh)
boost::shared_ptr< DiscreteContinuumMesh< ELEMENT_DIM, SPACE_DIM > > mpMesh
void SetReferenceConcentration(units::quantity< unit::concentration > referenceConcentration)
double ComputeConstantInUSourceTerm(const ChastePoint< SPACE_DIM > &rX, Element< ELEMENT_DIM, SPACE_DIM > *pElement)
units::quantity< unit::time > GetReferenceTimeScale()
Definition: BaseUnits.cpp:72
void AddDiscreteSource(boost::shared_ptr< DiscreteSource< SPACE_DIM > > pDiscreteSource)
void SetContinuumConstantInUTerm(units::quantity< unit::concentration_flow_rate > constantInUTerm)
std::vector< units::quantity< unit::concentration_flow_rate > > mDiscreteConstantSourceStrengths
void SetRegularGrid(boost::shared_ptr< RegularGrid< SPACE_DIM > > pRegularGrid)
std::vector< boost::shared_ptr< DiscreteSource< SPACE_DIM > > > GetDiscreteSources()
static BaseUnits * Instance()
Definition: BaseUnits.cpp:53
void SetIsotropicDiffusionConstant(units::quantity< unit::diffusivity > diffusivity)
std::vector< boost::shared_ptr< DiscreteSource< SPACE_DIM > > > mDiscreteSources
c_matrix< double, SPACE_DIM, SPACE_DIM > ComputeDiffusionTerm(const ChastePoint< SPACE_DIM > &)
units::quantity< unit::length > GetReferenceLengthScale()
Definition: BaseUnits.cpp:82