Chaste  Build::
LinearSteadyStateDiffusionReactionPde.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 "LinearSteadyStateDiffusionReactionPde.hpp"
38 #include "BaseUnits.hpp"
39 
40 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
42  AbstractDiscreteContinuumLinearEllipticPde<ELEMENT_DIM, ELEMENT_DIM>(),
43  mLinearInUTerm(0.0 * unit::per_second),
44  mDiscreteLinearSourceStrengths()
45 {
46 
47 }
48 
49 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
51 {
52 
53 }
54 
55 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
56 boost::shared_ptr<LinearSteadyStateDiffusionReactionPde<ELEMENT_DIM, SPACE_DIM> > LinearSteadyStateDiffusionReactionPde<ELEMENT_DIM, SPACE_DIM>::Create()
57 {
59  return pSelf;
60 }
61 
62 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
64  Element<ELEMENT_DIM, SPACE_DIM>* pElement)
65 {
67  {
68  if(pElement->GetIndex() >= mDiscreteLinearSourceStrengths.size())
69  {
70  EXCEPTION("Requested out of bound grid index in discrete sources. Maybe you forgot to update the source strengths.");
71  }
72  units::quantity<unit::rate> scaling_factor = (1.0/BaseUnits::Instance()->GetReferenceTimeScale());
73  return (mLinearInUTerm + mDiscreteLinearSourceStrengths[pElement->GetIndex()])/scaling_factor;
74  }
75  else
76  {
77  units::quantity<unit::rate> scaling_factor = (1.0/BaseUnits::Instance()->GetReferenceTimeScale());
78  return mLinearInUTerm/scaling_factor;
79  }
80 }
81 
82 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
84 {
86  {
87  if(gridIndex >= mDiscreteLinearSourceStrengths.size())
88  {
89  EXCEPTION("Requested out of bound grid index in discrete sources. Maybe you forgot to update the source strengths.");
90  }
92  }
93  else
94  {
95  return mLinearInUTerm;
96  }
97 }
98 
99 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
101 {
102  mLinearInUTerm = linearInUTerm;
103 }
104 
105 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
107 {
109  if(this->mUseRegularGrid)
110  {
111  if(!this->mpRegularGrid)
112  {
113  EXCEPTION("A grid has not been set for the determination of source strengths.");
114  }
115  mDiscreteLinearSourceStrengths = std::vector<units::quantity<unit::rate> >(this->mpRegularGrid->GetNumberOfPoints(), 0.0*unit::per_second);
116  for(unsigned idx=0; idx<this->mDiscreteSources.size(); idx++)
117  {
118  this->mDiscreteSources[idx]->SetRegularGrid(this->mpRegularGrid);
119  std::vector<units::quantity<unit::rate> > result = this->mDiscreteSources[idx]->GetLinearInURegularGridValues();
120  std::transform(mDiscreteLinearSourceStrengths.begin( ), mDiscreteLinearSourceStrengths.end( ),
121  result.begin( ), mDiscreteLinearSourceStrengths.begin( ),std::plus<units::quantity<unit::rate> >( ));
122  }
123  }
124  else
125  {
126  if(!this->mpMesh)
127  {
128  EXCEPTION("A mesh has not been set for the determination of source strengths.");
129  }
130  mDiscreteLinearSourceStrengths = std::vector<units::quantity<unit::rate> >(this->mpMesh->GetNumElements(), 0.0*unit::per_second);
131  for(unsigned idx=0; idx<this->mDiscreteSources.size(); idx++)
132  {
133  this->mDiscreteSources[idx]->SetMesh(this->mpMesh);
134  std::vector<units::quantity<unit::rate> > result = this->mDiscreteSources[idx]->GetLinearInUMeshValues();
135  std::transform(mDiscreteLinearSourceStrengths.begin( ), mDiscreteLinearSourceStrengths.end( ),
136  result.begin( ), mDiscreteLinearSourceStrengths.begin( ),std::plus<units::quantity<unit::rate> >( ));
137  }
138  }
139 }
140 
141 // Explicit instantiation
boost::shared_ptr< RegularGrid< SPACE_DIM > > mpRegularGrid
boost::shared_ptr< DiscreteContinuumMesh< ELEMENT_DIM, SPACE_DIM > > mpMesh
static boost::shared_ptr< LinearSteadyStateDiffusionReactionPde< ELEMENT_DIM, SPACE_DIM > > Create()
units::quantity< unit::time > GetReferenceTimeScale()
Definition: BaseUnits.cpp:72
double ComputeLinearInUCoeffInSourceTerm(const ChastePoint< SPACE_DIM > &rX, Element< ELEMENT_DIM, SPACE_DIM > *pElement)
static BaseUnits * Instance()
Definition: BaseUnits.cpp:53
std::vector< boost::shared_ptr< DiscreteSource< SPACE_DIM > > > mDiscreteSources
void SetContinuumLinearInUTerm(units::quantity< unit::rate > linearInUTerm)
std::vector< units::quantity< unit::rate > > mDiscreteLinearSourceStrengths