Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
EllipticGrowingDomainPdeModifier.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 "EllipticGrowingDomainPdeModifier.hpp"
37#include "CellBasedEllipticPdeSolver.hpp"
38#include "AveragedSourceEllipticPde.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 // If the solution at the previous timestep exists...
63 PetscInt previous_solution_size = 0;
64 if (this->mSolution)
65 {
66 VecGetSize(this->mSolution, &previous_solution_size);
67 }
68
69 // ...then record whether it is the correct size...
70 bool is_previous_solution_size_correct = (previous_solution_size == (int)this->mpFeMesh->GetNumNodes());
71
72 // ...and if it is, store it as an initial guess for the PDE solver
73 Vec initial_guess;
74 if (is_previous_solution_size_correct)
75 {
76 // This Vec is copied by the solver's Solve() method, so must be deleted here too
77 VecDuplicate(this->mSolution, &initial_guess);
78 VecCopy(this->mSolution, initial_guess);
79 PetscTools::Destroy(this->mSolution);
80 }
81
82 // Add the BCs to the BCs container
83 std::shared_ptr<BoundaryConditionsContainer<DIM,DIM,1> > p_bcc = this->ConstructBoundaryConditionsContainer();
84
85 // Use CellBasedEllipticPdeSolver as cell wise PDE
86 CellBasedEllipticPdeSolver<DIM> solver(this->mpFeMesh,
87 boost::static_pointer_cast<AbstractLinearEllipticPde<DIM,DIM> >(this->GetPde()).get(),
88 p_bcc.get());
89
90 // If we have an initial guess, use this when solving the system...
91 if (is_previous_solution_size_correct)
92 {
93 this->mSolution = solver.Solve(initial_guess);
94 PetscTools::Destroy(initial_guess);
95 }
96 else // ...otherwise do not supply one
97 {
98 // The solver creates a Vec, so we have to keep a handle on the old one to destroy it
99 Vec old_solution_copy = this->mSolution;
100
101 this->mSolution = solver.Solve();
102
103 // On the first go round the vector has yet to be initialised, so we don't destroy it
104 if (old_solution_copy != nullptr)
105 {
106 PetscTools::Destroy(old_solution_copy);
107 }
108 }
109
110 this->UpdateCellData(rCellPopulation);
111}
112
113template<unsigned DIM>
115{
116 if (boost::dynamic_pointer_cast<AveragedSourceEllipticPde<DIM> >(this->GetPde()))
117 {
118 EXCEPTION("EllipticGrowingDomainPdeModifier cannot be used with an AveragedSourceEllipticPde. Use an EllipticBoxDomainPdeModifier instead.");
119 }
120
121 AbstractGrowingDomainPdeModifier<DIM>::SetupSolve(rCellPopulation, outputDirectory);
122
123 // Call these methods to solve the PDE on the initial step and output the results
124 UpdateAtEndOfTimeStep(rCellPopulation);
125 this->UpdateAtEndOfOutputTimeStep(rCellPopulation);
126}
127
128template<unsigned DIM>
129std::shared_ptr<BoundaryConditionsContainer<DIM,DIM,1> > EllipticGrowingDomainPdeModifier<DIM>::ConstructBoundaryConditionsContainer()
130{
131 std::shared_ptr<BoundaryConditionsContainer<DIM,DIM,1> > p_bcc(new BoundaryConditionsContainer<DIM,DIM,1>(false));
132
133 // To be well-defined, elliptic PDE problems on growing domains require Dirichlet boundary conditions
134 assert(!(this->IsNeumannBoundaryCondition()));
135 for (typename TetrahedralMesh<DIM,DIM>::BoundaryNodeIterator node_iter = this->mpFeMesh->GetBoundaryNodeIteratorBegin();
136 node_iter != this->mpFeMesh->GetBoundaryNodeIteratorEnd();
137 ++node_iter)
138 {
139 p_bcc->AddDirichletBoundaryCondition(*node_iter, this->mpBoundaryCondition.get());
140 }
141
142 return p_bcc;
143}
144
145template<unsigned DIM>
147{
148 // No parameters to output, so just call method on direct parent class
150}
151
152// Explicit instantiation
156
157// Serialization for Boost >= 1.36
#define EXCEPTION(message)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void OutputSimulationModifierParameters(out_stream &rParamsFile)
std::vector< Node< SPACE_DIM > * >::const_iterator BoundaryNodeIterator
virtual void SetupSolve(AbstractCellPopulation< DIM, DIM > &rCellPopulation, std::string outputDirectory)
virtual void SetupSolve(AbstractCellPopulation< DIM, DIM > &rCellPopulation, std::string outputDirectory)
virtual void UpdateAtEndOfTimeStep(AbstractCellPopulation< DIM, DIM > &rCellPopulation)
void OutputSimulationModifierParameters(out_stream &rParamsFile)
EllipticGrowingDomainPdeModifier(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)
virtual std::shared_ptr< BoundaryConditionsContainer< DIM, DIM, 1 > > ConstructBoundaryConditionsContainer()
static void Destroy(Vec &rVec)