Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
ParabolicGrowingDomainPdeModifier.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, 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 above 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
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#include "ParabolicGrowingDomainPdeModifier.hpp"
37#include "CellBasedParabolicPdeSolver.hpp"
38#include "AveragedSourceParabolicPde.hpp"
39
40template<unsigned DIM>
42 boost::shared_ptr<AbstractBoundaryCondition<DIM> > pBoundaryCondition,
43 bool isNeumannBoundaryCondition,
44 Vec solution)
46 pBoundaryCondition,
47 isNeumannBoundaryCondition,
48 solution)
49{
50}
51
52template<unsigned DIM>
56
57template<unsigned DIM>
59{
60 this->GenerateFeMesh(rCellPopulation);
61
62 // Set up boundary conditions
63 std::shared_ptr<BoundaryConditionsContainer<DIM,DIM,1> > p_bcc = ConstructBoundaryConditionsContainer();
64
65 // Construct the solution vector from cell data (takes care of cells dividing);
66 UpdateSolutionVector(rCellPopulation);
67
68 // Use CellBasedParabolicPdeSolver as cell wise PDE
69 CellBasedParabolicPdeSolver<DIM> solver(this->mpFeMesh,
70 boost::static_pointer_cast<AbstractLinearParabolicPde<DIM,DIM> >(this->mpPde).get(),
71 p_bcc.get());
72
74 SimulationTime* p_simulation_time = SimulationTime::Instance();
75 double current_time = p_simulation_time->GetTime();
76 double dt = p_simulation_time->GetTimeStep();
77 solver.SetTimes(current_time,current_time + dt);
78 solver.SetTimeStep(dt);
79
80 // Use previous solution as the initial condition
81 Vec previous_solution = this->mSolution;
82 solver.SetInitialCondition(previous_solution);
83
84 // Note that the linear solver creates a vector, so we have to keep a handle on the old one
85 // in order to destroy it
86 this->mSolution = solver.Solve();
87 PetscTools::Destroy(previous_solution);
88 this->UpdateCellData(rCellPopulation);
89}
90
91template<unsigned DIM>
93{
94 AbstractGrowingDomainPdeModifier<DIM>::SetupSolve(rCellPopulation, outputDirectory);
95
96 if (boost::dynamic_pointer_cast<AveragedSourceParabolicPde<DIM> >(this->mpPde))
97 {
98 EXCEPTION("ParabolicGrowingDomainPdeModifier cannot be used with an AveragedSourceParabolicPde. Use a ParabolicBoxDomainPdeModifier instead.");
99 }
100
101 // Setup a finite element mesh on which to save the initial condition
102 this->GenerateFeMesh(rCellPopulation);
103
104 // Copy the cell data to mSolution (this is the initial condition)
105 UpdateSolutionVector(rCellPopulation);
106
107 // Output the initial conditions on FeMesh
108 this->UpdateAtEndOfOutputTimeStep(rCellPopulation);
109}
110
111template<unsigned DIM>
112std::shared_ptr<BoundaryConditionsContainer<DIM,DIM,1> > ParabolicGrowingDomainPdeModifier<DIM>::ConstructBoundaryConditionsContainer()
113{
114 std::shared_ptr<BoundaryConditionsContainer<DIM,DIM,1> > p_bcc(new BoundaryConditionsContainer<DIM,DIM,1>(false));
115
116 if (this->IsNeumannBoundaryCondition())
117 {
118 // Impose any Neumann boundary conditions
119 for (typename TetrahedralMesh<DIM,DIM>::BoundaryElementIterator elem_iter = this->mpFeMesh->GetBoundaryElementIteratorBegin();
120 elem_iter != this->mpFeMesh->GetBoundaryElementIteratorEnd();
121 ++elem_iter)
122 {
123 p_bcc->AddNeumannBoundaryCondition(*elem_iter, this->mpBoundaryCondition.get());
124 }
125 }
126 else
127 {
128 // Impose any Dirichlet boundary conditions
129 for (typename TetrahedralMesh<DIM,DIM>::BoundaryNodeIterator node_iter = this->mpFeMesh->GetBoundaryNodeIteratorBegin();
130 node_iter != this->mpFeMesh->GetBoundaryNodeIteratorEnd();
131 ++node_iter)
132 {
133 p_bcc->AddDirichletBoundaryCondition(*node_iter, this->mpBoundaryCondition.get());
134 }
135 }
136
137 return p_bcc;
138}
139
140template<unsigned DIM>
142{
143 // Clear (if it's not the first time) and resize the solution vector
144 if (this->mSolution)
145 {
146 PetscTools::Destroy(this->mSolution);
147 }
148 this->mSolution = PetscTools::CreateAndSetVec(this->mpFeMesh->GetNumNodes(), 0.0);
149
150 std::string& variable_name = this->mDependentVariableName;
151
152 for (typename TetrahedralMesh<DIM,DIM>::NodeIterator node_iter = this->mpFeMesh->GetNodeIteratorBegin();
153 node_iter != this->mpFeMesh->GetNodeIteratorEnd();
154 ++node_iter)
155 {
156 // Loop over nodes of the finite element mesh and get appropriate solution values from CellData
157 for (typename TetrahedralMesh<DIM,DIM>::NodeIterator node_iter = this->mpFeMesh->GetNodeIteratorBegin();
158 node_iter != this->mpFeMesh->GetNodeIteratorEnd();
159 ++node_iter)
160 {
161 unsigned node_index = node_iter->GetIndex();
162 bool dirichlet_bc_applies = (node_iter->IsBoundaryNode()) && (!(this->IsNeumannBoundaryCondition()));
163 double boundary_value = this->GetBoundaryCondition()->GetValue(node_iter->rGetLocation());
164
165 double solution_at_node = rCellPopulation.GetCellDataItemAtPdeNode(node_index, variable_name, dirichlet_bc_applies, boundary_value);
166
167 PetscVecTools::SetElement(this->mSolution, node_index, solution_at_node);
168 }
169 }
170}
171
172template<unsigned DIM>
174{
175 // No parameters to output, so just call method on direct parent class
177}
178
179// Explicit instantiation
183
184// Serialization for Boost >= 1.36
187
#define EXCEPTION(message)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
virtual double GetCellDataItemAtPdeNode(unsigned pdeNodeIndex, std::string &rVariableName, bool dirichletBoundaryConditionApplies=false, double dirichletBoundaryValue=0.0)=0
void SetTimes(double tStart, double tEnd)
void OutputSimulationModifierParameters(out_stream &rParamsFile)
std::vector< Node< SPACE_DIM > * >::const_iterator BoundaryNodeIterator
virtual void SetupSolve(AbstractCellPopulation< DIM, DIM > &rCellPopulation, std::string outputDirectory)
std::vector< BoundaryElement< ELEMENT_DIM-1, SPACE_DIM > * >::const_iterator BoundaryElementIterator
virtual void SetupSolve(AbstractCellPopulation< DIM, DIM > &rCellPopulation, std::string outputDirectory)
virtual std::shared_ptr< BoundaryConditionsContainer< DIM, DIM, 1 > > ConstructBoundaryConditionsContainer()
void OutputSimulationModifierParameters(out_stream &rParamsFile)
virtual void UpdateAtEndOfTimeStep(AbstractCellPopulation< DIM, DIM > &rCellPopulation)
ParabolicGrowingDomainPdeModifier(boost::shared_ptr< AbstractLinearPde< DIM, DIM > > pPde=boost::shared_ptr< AbstractLinearPde< DIM, DIM > >(), boost::shared_ptr< AbstractBoundaryCondition< DIM > > pBoundaryCondition=boost::shared_ptr< AbstractBoundaryCondition< DIM > >(), bool isNeumannBoundaryCondition=true, Vec solution=nullptr)
void UpdateSolutionVector(AbstractCellPopulation< DIM, DIM > &rCellPopulation)
static Vec CreateAndSetVec(int size, double value)
static void Destroy(Vec &rVec)
static void SetElement(Vec vector, PetscInt row, double value)
double GetTime() const
double GetTimeStep() const
static SimulationTime * Instance()