Chaste  Release::3.4
CellBasedPdeHandlerOnCuboid.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 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 
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 "CellBasedPdeHandlerOnCuboid.hpp"
37 #include "ConstBoundaryCondition.hpp"
38 
39 template<unsigned DIM>
41  bool deleteMemberPointersInDestructor)
42  : CellBasedPdeHandler<DIM>(pCellPopulation, deleteMemberPointersInDestructor)
43 {
44 }
45 
46 template<unsigned DIM>
48 {
49  // Delete all boundary conditions
50  for (unsigned i=0; i<mConstBoundaryConditions.size(); i++)
51  {
52  delete mConstBoundaryConditions[i];
53  }
54 }
55 
56 template<unsigned DIM>
57 std::auto_ptr<BoundaryConditionsContainer<DIM,DIM,1> > CellBasedPdeHandlerOnCuboid<DIM>::ConstructBoundaryConditionsContainer(
60 {
61  // Not using the inputs as there's only one BC
62  assert(DIM==2);
63 
64  std::auto_ptr<BoundaryConditionsContainer<DIM,DIM,1> > p_bcc(new BoundaryConditionsContainer<DIM,DIM,1>(false));
65 
66  // Use these two vectors to define what's happening on the top right bottom and left boundaries
67 
68  // Specify which sides are Neumann boundaries
69  c_vector<bool,4> are_neumann_boundaries;
70  are_neumann_boundaries[0] = false; // Top
71  are_neumann_boundaries[1] = true; // Right
72  are_neumann_boundaries[2] = false; // Bottom
73  are_neumann_boundaries[3] = true; // Left
74 
75  // Specify the value of the boundary condition on each boundary
76  c_vector<double,4> boundary_condition_values;
77  boundary_condition_values[0] = 1.0; // Top
78  boundary_condition_values[1] = 1.0; // Right
79  boundary_condition_values[2] = 1.0; // Bottom
80  boundary_condition_values[3] = 1.0; // Left
81 
82  // Delete all previous boundary conditions
83  for (unsigned i=0; i<mConstBoundaryConditions.size(); i++)
84  {
85  delete mConstBoundaryConditions[i];
86  }
87  mConstBoundaryConditions.clear();
88 
89  mConstBoundaryConditions.push_back(new ConstBoundaryCondition<DIM>(boundary_condition_values[0]));
90  mConstBoundaryConditions.push_back(new ConstBoundaryCondition<DIM>(boundary_condition_values[1]));
91  mConstBoundaryConditions.push_back(new ConstBoundaryCondition<DIM>(boundary_condition_values[2]));
92  mConstBoundaryConditions.push_back(new ConstBoundaryCondition<DIM>(boundary_condition_values[3]));
93 
94  ChasteCuboid<DIM> cuboid = pMesh->CalculateBoundingBox();
95 
96  double left = cuboid.rGetLowerCorner()[0];
97  double bottom = cuboid.rGetLowerCorner()[1];
98  double right = cuboid.rGetUpperCorner()[0];
99  double top = cuboid.rGetUpperCorner()[1];
100  double fudge_factor = 1e-6;
101 
102  // Apply Neumann boundary conditions
104  elem_iter != pMesh->GetBoundaryElementIteratorEnd();
105  ++elem_iter)
106  {
107  double x_1 = (*elem_iter)->GetNodeLocation(0)[0];
108 // double y_1 = (*elem_iter)->GetNodeLocation(0)[1];
109  double x_2 = (*elem_iter)->GetNodeLocation(1)[0];
110 // double y_2 = (*elem_iter)->GetNodeLocation(1)[1];
111 
112  assert(!are_neumann_boundaries[0]);
113 // if (are_neumann_boundaries[0]) // Top is Neumann boundary
114 // {
115 // if ( (y_1 > (top-fudge_factor) ) && (y_2 > (top-fudge_factor) ))
116 // {
117 // p_bcc->AddNeumannBoundaryCondition(*elem_iter, mConstBoundaryConditions[0]);
118 // }
119 // }
120  if (are_neumann_boundaries[1]) // Right is Neumann boundary
121  {
122  if ( (x_1 > (right-fudge_factor) ) && (x_2 > (right-fudge_factor) ))
123  {
124  p_bcc->AddNeumannBoundaryCondition(*elem_iter, mConstBoundaryConditions[1]);
125  }
126  }
127  assert(!are_neumann_boundaries[2]);
128 // if (are_neumann_boundaries[2]) // Bottom is Neumann boundary
129 // {
130 // if ( (y_1 < (bottom+fudge_factor) ) && (y_2 < (bottom+fudge_factor) ))
131 // {
132 // p_bcc->AddNeumannBoundaryCondition(*elem_iter, mConstBoundaryConditions[2]);
133 // }
134 // }
135  if (are_neumann_boundaries[3]) // Left is Neumann Boundary
136  {
137  if ( (x_1 > (left+fudge_factor) ) && (x_2 < (left+fudge_factor) ))
138  {
139  p_bcc->AddNeumannBoundaryCondition(*elem_iter, mConstBoundaryConditions[3]);
140  }
141  }
142  }
143 
144  // Apply Dirichlet boundaries
146  node_iter != pMesh->GetBoundaryNodeIteratorEnd();
147  ++node_iter)
148  {
149 // double x = (*node_iter)->GetPoint()[0];
150  double y = (*node_iter)->GetPoint()[1];
151 
152  if (!are_neumann_boundaries[0]) // Top is Dirichlet boundary
153  {
154  if (y > top-fudge_factor)
155  {
156  p_bcc->AddDirichletBoundaryCondition(*node_iter, mConstBoundaryConditions[0]);
157  }
158  }
159  assert(are_neumann_boundaries[1]);
160 // if (!are_neumann_boundaries[1]) // Right is Dirichlet boundary
161 // {
162 // if (x > right-fudge_factor)
163 // {
164 // p_bcc->AddDirichletBoundaryCondition(*node_iter, mConstBoundaryConditions[1]);
165 // }
166 // }
167  if (!are_neumann_boundaries[2]) // Bottom is Dirichlet boundary
168  {
169  if (y < bottom+fudge_factor)
170  {
171  p_bcc->AddDirichletBoundaryCondition(*node_iter, mConstBoundaryConditions[2]);
172  }
173  }
174  assert(are_neumann_boundaries[3]);
175 // if (!are_neumann_boundaries[3]) // Left is Dirichlet boundary
176 // {
177 // if (x < left+fudge_factor)
178 // {
179 // p_bcc->AddDirichletBoundaryCondition(*node_iter, mConstBoundaryConditions[3]);
180 // }
181 // }
182  }
183 
184  return p_bcc;
185 }
186 
187 template<unsigned DIM>
189 {
191 }
192 
193 // Serialization for Boost >= 1.36
196 
197 template class CellBasedPdeHandlerOnCuboid<1>;
199 template class CellBasedPdeHandlerOnCuboid<2>;
200 template class CellBasedPdeHandlerOnCuboid<3>;
BoundaryElementIterator GetBoundaryElementIteratorBegin() const
BoundaryNodeIterator GetBoundaryNodeIteratorBegin() const
const ChastePoint< SPACE_DIM > & rGetUpperCorner() const
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
std::auto_ptr< BoundaryConditionsContainer< DIM, DIM, 1 > > ConstructBoundaryConditionsContainer(PdeAndBoundaryConditions< DIM > *pPdeAndBc, TetrahedralMesh< DIM, DIM > *pMesh)
CellBasedPdeHandlerOnCuboid(AbstractCellPopulation< DIM > *pCellPopulation, bool deleteMemberPointersInDestructor=false)
virtual void OutputParameters(out_stream &rParamsFile)
virtual void OutputParameters(out_stream &rParamsFile)
BoundaryNodeIterator GetBoundaryNodeIteratorEnd() const
ChasteCuboid< SPACE_DIM > CalculateBoundingBox(const std::vector< Node< SPACE_DIM > * > &rNodes) const
BoundaryElementIterator GetBoundaryElementIteratorEnd() const
const ChastePoint< SPACE_DIM > & rGetLowerCorner() const