Chaste Commit::43b116bb45f11066c455b15e05c77f8bbe23ac85
EllipticBoxDomainPdeModifier.cpp
1/*
2
3Copyright (c) 2005-2025, 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 "EllipticBoxDomainPdeModifier.hpp"
37#include "SimpleLinearEllipticSolver.hpp"
38
39template<unsigned DIM>
41 boost::shared_ptr<AbstractBoundaryCondition<DIM> > pBoundaryCondition,
42 bool isNeumannBoundaryCondition,
43 boost::shared_ptr<ChasteCuboid<DIM> > pMeshCuboid,
44 double stepSize,
45 Vec solution)
47 pBoundaryCondition,
48 isNeumannBoundaryCondition,
49 pMeshCuboid,
50 stepSize,
51 solution)
52{
53}
54
55template<unsigned DIM>
57{
58 // Set up boundary conditions
59 std::shared_ptr<BoundaryConditionsContainer<DIM,DIM,1> > p_bcc = ConstructBoundaryConditionsContainer(rCellPopulation);
60
61 this->UpdateCellPdeElementMap(rCellPopulation);
62
63 // When using a PDE mesh which doesn't coincide with the cells, we must set up the source terms before solving the PDE.
64 // Pass in already updated CellPdeElementMap to speed up finding cells.
65 this->SetUpSourceTermsForAveragedSourcePde(this->mpFeMesh, &this->mCellPdeElementMap);
66
67 // Use SimpleLinearEllipticSolver as Averaged Source PDE
69 SimpleLinearEllipticSolver<DIM,DIM> solver(this->mpFeMesh,
70 boost::static_pointer_cast<AbstractLinearEllipticPde<DIM,DIM> >(this->GetPde()).get(),
71 p_bcc.get());
72
74 Vec old_solution_copy = this->mSolution;
75 this->mSolution = solver.Solve();
76 if (old_solution_copy != nullptr)
77 {
78 PetscTools::Destroy(old_solution_copy);
79 }
80
81 this->UpdateCellData(rCellPopulation);
82}
83
84template<unsigned DIM>
85void EllipticBoxDomainPdeModifier<DIM>::SetupSolve(AbstractCellPopulation<DIM,DIM>& rCellPopulation, std::string outputDirectory)
86{
87 AbstractBoxDomainPdeModifier<DIM>::SetupSolve(rCellPopulation,outputDirectory);
88
89 // Call these methods to solve the PDE on the initial step and output the results
90 UpdateAtEndOfTimeStep(rCellPopulation);
91 this->UpdateAtEndOfOutputTimeStep(rCellPopulation);
92}
93
94template<unsigned DIM>
95std::shared_ptr<BoundaryConditionsContainer<DIM,DIM,1> > EllipticBoxDomainPdeModifier<DIM>::ConstructBoundaryConditionsContainer(AbstractCellPopulation<DIM,DIM>& rCellPopulation)
96{
97
98 std::shared_ptr<BoundaryConditionsContainer<DIM,DIM,1> > p_bcc(new BoundaryConditionsContainer<DIM,DIM,1>(false));
99
100 // To be well-defined, elliptic PDE problems on box domains require at least some Dirichlet boundary conditions
102 assert(!(this->IsNeumannBoundaryCondition()));
103
104 this->ConstructBoundaryConditionsContainerHelper(rCellPopulation,p_bcc);
105
106 return p_bcc;
107}
108
109template<unsigned DIM>
111{
112 // No parameters to output, so just call method on direct parent class
114}
115
116// Explicit instantiation
120
121// Serialization for Boost >= 1.36
124
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void OutputSimulationModifierParameters(out_stream &rParamsFile) override
void SetupSolve(AbstractCellPopulation< DIM, DIM > &rCellPopulation, std::string outputDirectory) override
void OutputSimulationModifierParameters(out_stream &rParamsFile) override
void UpdateAtEndOfTimeStep(AbstractCellPopulation< DIM, DIM > &rCellPopulation) override
virtual std::shared_ptr< BoundaryConditionsContainer< DIM, DIM, 1 > > ConstructBoundaryConditionsContainer(AbstractCellPopulation< DIM, DIM > &rCellPopulation)
void SetupSolve(AbstractCellPopulation< DIM, DIM > &rCellPopulation, std::string outputDirectory) override
EllipticBoxDomainPdeModifier(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, boost::shared_ptr< ChasteCuboid< DIM > > pMeshCuboid=boost::shared_ptr< ChasteCuboid< DIM > >(), double stepSize=1.0, Vec solution=nullptr)
static void Destroy(Vec &rVec)