Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
EllipticBoxDomainPdeModifier.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 "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>
59
60template<unsigned DIM>
62{
63 // Set up boundary conditions
64 std::shared_ptr<BoundaryConditionsContainer<DIM,DIM,1> > p_bcc = ConstructBoundaryConditionsContainer(rCellPopulation);
65
66 this->UpdateCellPdeElementMap(rCellPopulation);
67
68 // When using a PDE mesh which doesn't coincide with the cells, we must set up the source terms before solving the PDE.
69 // Pass in already updated CellPdeElementMap to speed up finding cells.
70 this->SetUpSourceTermsForAveragedSourcePde(this->mpFeMesh, &this->mCellPdeElementMap);
71
72 // Use SimpleLinearEllipticSolver as Averaged Source PDE
74 SimpleLinearEllipticSolver<DIM,DIM> solver(this->mpFeMesh,
75 boost::static_pointer_cast<AbstractLinearEllipticPde<DIM,DIM> >(this->GetPde()).get(),
76 p_bcc.get());
77
79 Vec old_solution_copy = this->mSolution;
80 this->mSolution = solver.Solve();
81 if (old_solution_copy != nullptr)
82 {
83 PetscTools::Destroy(old_solution_copy);
84 }
85
86 this->UpdateCellData(rCellPopulation);
87}
88
89template<unsigned DIM>
90void EllipticBoxDomainPdeModifier<DIM>::SetupSolve(AbstractCellPopulation<DIM,DIM>& rCellPopulation, std::string outputDirectory)
91{
92 AbstractBoxDomainPdeModifier<DIM>::SetupSolve(rCellPopulation,outputDirectory);
93
94 // Call these methods to solve the PDE on the initial step and output the results
95 UpdateAtEndOfTimeStep(rCellPopulation);
96 this->UpdateAtEndOfOutputTimeStep(rCellPopulation);
97}
98
99template<unsigned DIM>
100std::shared_ptr<BoundaryConditionsContainer<DIM,DIM,1> > EllipticBoxDomainPdeModifier<DIM>::ConstructBoundaryConditionsContainer(AbstractCellPopulation<DIM,DIM>& rCellPopulation)
101{
102 std::shared_ptr<BoundaryConditionsContainer<DIM,DIM,1> > p_bcc(new BoundaryConditionsContainer<DIM,DIM,1>(false));
103
104 // To be well-defined, elliptic PDE problems on box domains require at least some Dirichlet boundary conditions
106 assert(!(this->IsNeumannBoundaryCondition()));
107
108 if (!this->mSetBcsOnBoxBoundary)
109 {
110 // Get the set of coarse element indices that contain cells
111 std::set<unsigned> coarse_element_indices_in_map;
112 for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = rCellPopulation.Begin();
113 cell_iter != rCellPopulation.End();
114 ++cell_iter)
115 {
116 coarse_element_indices_in_map.insert(this->mCellPdeElementMap[*cell_iter]);
117 }
118
119 // Find the node indices associated with elements whose indices are NOT in the set coarse_element_indices_in_map
120 std::set<unsigned> coarse_mesh_boundary_node_indices;
121 for (unsigned i=0; i<this->mpFeMesh->GetNumElements(); i++)
122 {
123 if (coarse_element_indices_in_map.find(i) == coarse_element_indices_in_map.end())
124 {
125 Element<DIM,DIM>* p_element = this->mpFeMesh->GetElement(i);
126 for (unsigned j=0; j<DIM+1; j++)
127 {
128 unsigned node_index = p_element->GetNodeGlobalIndex(j);
129 coarse_mesh_boundary_node_indices.insert(node_index);
130 }
131 }
132 }
133
134 // Apply boundary condition to the nodes in the set coarse_mesh_boundary_node_indices
135 for (std::set<unsigned>::iterator iter = coarse_mesh_boundary_node_indices.begin();
136 iter != coarse_mesh_boundary_node_indices.end();
137 ++iter)
138 {
139 p_bcc->AddDirichletBoundaryCondition(this->mpFeMesh->GetNode(*iter), this->mpBoundaryCondition.get(), 0, false);
140 }
141 }
142 else // Apply BC at boundary nodes of box domain FE mesh
143 {
144 for (typename TetrahedralMesh<DIM,DIM>::BoundaryNodeIterator node_iter = this->mpFeMesh->GetBoundaryNodeIteratorBegin();
145 node_iter != this->mpFeMesh->GetBoundaryNodeIteratorEnd();
146 ++node_iter)
147 {
148 p_bcc->AddDirichletBoundaryCondition(*node_iter, this->mpBoundaryCondition.get());
149 }
150 }
151
152 return p_bcc;
153}
154
155template<unsigned DIM>
157{
158 // No parameters to output, so just call method on direct parent class
160}
161
162// Explicit instantiation
166
167// Serialization for Boost >= 1.36
170
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void OutputSimulationModifierParameters(out_stream &rParamsFile)
virtual void SetupSolve(AbstractCellPopulation< DIM, DIM > &rCellPopulation, std::string outputDirectory)
unsigned GetNodeGlobalIndex(unsigned localIndex) const
std::vector< Node< SPACE_DIM > * >::const_iterator BoundaryNodeIterator
virtual void SetupSolve(AbstractCellPopulation< DIM, DIM > &rCellPopulation, std::string outputDirectory)
virtual void UpdateAtEndOfTimeStep(AbstractCellPopulation< DIM, DIM > &rCellPopulation)
virtual std::shared_ptr< BoundaryConditionsContainer< DIM, DIM, 1 > > ConstructBoundaryConditionsContainer(AbstractCellPopulation< DIM, DIM > &rCellPopulation)
void OutputSimulationModifierParameters(out_stream &rParamsFile)
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)