Chaste  Build::
AbstractDiscreteContinuumNonLinearEllipticPde.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 "AbstractDiscreteContinuumNonLinearEllipticPde.hpp"
38 
39 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
41  AbstractNonlinearEllipticPde<SPACE_DIM>(),
42  mDiffusionTensor(identity_matrix<double>(SPACE_DIM)),
43  mDiffusivity(1.0*unit::metre_squared_per_second),
44  mConstantInUTerm(),
45  mLinearInUTerm(),
46  mDiscreteSources(),
47  mpRegularGrid(),
48  mpMesh(),
49  mUseRegularGrid(true),
50  mDiscreteConstantSourceStrengths(),
51  mDiscreteLinearSourceStrengths()
52 {
53  mDiffusionTensor *= mDiffusivity.value();
54 }
55 
56 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
58 {
59 
60 }
61 
62 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
64 {
65  mDiscreteSources.push_back(pDiscreteSource);
66 }
67 
68 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
70 {
71  return mDiffusivity;
72 }
73 
74 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
75 units::quantity<unit::concentration_flow_rate> AbstractDiscreteContinuumNonLinearEllipticPde<ELEMENT_DIM, SPACE_DIM>::ComputeConstantInUSourceTerm(unsigned gridIndex)
76 {
78  {
79  if(gridIndex >= mDiscreteConstantSourceStrengths.size())
80  {
81  EXCEPTION("Requested out of bound grid index in discrete sources. Maybe you forgot to update the source strengths.");
82  }
84  }
85  else
86  {
87  return mConstantInUTerm;
88  }
89 }
90 
91 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
93 {
95  {
96  if(gridIndex >= mDiscreteLinearSourceStrengths.size())
97  {
98  EXCEPTION("Requested out of bound grid index in discrete sources. Maybe you forgot to update the source strengths.");
99  }
101  }
102  else
103  {
104  return mLinearInUTerm;
105  }
106 }
107 
108 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
109 std::vector<boost::shared_ptr<DiscreteSource<SPACE_DIM> > > AbstractDiscreteContinuumNonLinearEllipticPde<ELEMENT_DIM, SPACE_DIM>::GetDiscreteSources()
110 {
111  return mDiscreteSources;
112 }
113 
114 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
115 void AbstractDiscreteContinuumNonLinearEllipticPde<ELEMENT_DIM, SPACE_DIM>::SetContinuumConstantInUTerm(units::quantity<unit::concentration_flow_rate> constantInUTerm)
116 {
117  mConstantInUTerm = constantInUTerm;
118 }
119 
120 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
122 {
123  mDiffusivity = diffusivity;
124  mDiffusionTensor = identity_matrix<double>(SPACE_DIM)* double(mDiffusivity/unit::metre_squared_per_second);
125 }
126 
127 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
129 {
130  mLinearInUTerm = linearInUTerm;
131 }
132 
133 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
135 {
136  mpRegularGrid = pRegularGrid;
137 }
138 
139 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
141 {
142  mpMesh = pMesh;
143 }
144 
145 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
147 {
148  mUseRegularGrid = useRegularGrid;
149 }
150 
151 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
153 {
154  if(mUseRegularGrid)
155  {
156  if(!mpRegularGrid)
157  {
158  EXCEPTION("A grid has not been set for the determination of source strengths.");
159  }
160  mDiscreteConstantSourceStrengths = std::vector<units::quantity<unit::concentration_flow_rate> >(mpRegularGrid->GetNumberOfPoints(), 0.0*unit::mole_per_metre_cubed_per_second);
161  mDiscreteLinearSourceStrengths = std::vector<units::quantity<unit::rate> >(mpRegularGrid->GetNumberOfPoints(), 0.0*unit::per_second);
162 
163  for(unsigned idx=0; idx<mDiscreteSources.size(); idx++)
164  {
165  mDiscreteSources[idx]->SetRegularGrid(mpRegularGrid);
166  std::vector<units::quantity<unit::rate> > result = mDiscreteSources[idx]->GetLinearInURegularGridValues();
167  std::transform(mDiscreteLinearSourceStrengths.begin( ), mDiscreteLinearSourceStrengths.end( ),
168  result.begin( ), mDiscreteLinearSourceStrengths.begin( ),std::plus<units::quantity<unit::rate> >( ));
169 
170  std::vector<units::quantity<unit::concentration_flow_rate> > result2 = mDiscreteSources[idx]->GetConstantInURegularGridValues();
172  result2.begin( ), mDiscreteConstantSourceStrengths.begin( ),std::plus<units::quantity<unit::concentration_flow_rate> >( ));
173  }
174  }
175  else
176  {
177  if(!mpMesh)
178  {
179  EXCEPTION("A mesh has not been set for the determination of source strengths.");
180  }
181  }
182 }
183 
184 // Explicit instantiation
virtual units::quantity< unit::rate > ComputeLinearInUCoeffInSourceTerm(unsigned gridIndex=0)
void SetRegularGrid(boost::shared_ptr< RegularGrid< SPACE_DIM > > pRegularGrid)
boost::shared_ptr< TetrahedralMesh< ELEMENT_DIM, SPACE_DIM > > mpMesh
std::vector< boost::shared_ptr< DiscreteSource< SPACE_DIM > > > mDiscreteSources
void SetMesh(boost::shared_ptr< TetrahedralMesh< ELEMENT_DIM, SPACE_DIM > > pMesh)
virtual units::quantity< unit::concentration_flow_rate > ComputeConstantInUSourceTerm(unsigned gridIndex=0)
std::vector< units::quantity< unit::rate > > mDiscreteLinearSourceStrengths
void SetIsotropicDiffusionConstant(units::quantity< unit::diffusivity > diffusivity)
void SetContinuumLinearInUTerm(units::quantity< unit::rate > linearInUTerm)
std::vector< boost::shared_ptr< DiscreteSource< SPACE_DIM > > > GetDiscreteSources()
void AddDiscreteSource(boost::shared_ptr< DiscreteSource< SPACE_DIM > > pDiscreteSource)
std::vector< units::quantity< unit::concentration_flow_rate > > mDiscreteConstantSourceStrengths
units::quantity< unit::concentration_flow_rate > mConstantInUTerm
void SetContinuumConstantInUTerm(units::quantity< unit::concentration_flow_rate > constantInUTerm)