Chaste  Release::3.4
AbstractFeSurfaceIntegralAssembler.hpp
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 #ifndef ABSTRACTFESURFACENTEGRALASSEMBLER_HPP_
37 #define ABSTRACTFESURFACENTEGRALASSEMBLER_HPP_
38 
39 #include "AbstractFeAssemblerCommon.hpp"
40 #include "GaussianQuadratureRule.hpp"
41 #include "BoundaryConditionsContainer.hpp"
42 #include "PetscVecTools.hpp"
43 #include "PetscMatTools.hpp"
44 
45 
60 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
61 class AbstractFeSurfaceIntegralAssembler : public AbstractFeAssemblerCommon<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM,true,false,NORMAL>
62 {
63 protected:
66 
69 
72 
74  typedef LinearBasisFunction<ELEMENT_DIM-1> SurfaceBasisFunction;
75 
89  virtual c_vector<double, PROBLEM_DIM*ELEMENT_DIM> ComputeVectorSurfaceTerm(
90  const BoundaryElement<ELEMENT_DIM-1,SPACE_DIM>& rSurfaceElement,
91  c_vector<double, ELEMENT_DIM>& rPhi,
93  {
94  // If this line is reached this means this method probably hasn't been over-ridden correctly in
95  // the concrete class
97  return zero_vector<double>(ELEMENT_DIM*PROBLEM_DIM);
98  }
99 
109  virtual void AssembleOnSurfaceElement(const BoundaryElement<ELEMENT_DIM-1,SPACE_DIM>& rSurfaceElement,
110  c_vector<double, PROBLEM_DIM*ELEMENT_DIM>& rBSurfElem);
111 
112 
116  void DoAssemble();
117 
118 
119 public:
128 
133 
139  {
140  assert(pBoundaryConditions);
141  this->mpBoundaryConditions = pBoundaryConditions;
142  }
143 };
144 
145 
146 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
150  : AbstractFeAssemblerCommon<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM,true,false,NORMAL>(),
151  mpMesh(pMesh),
152  mpBoundaryConditions(pBoundaryConditions)
153 {
154  assert(pMesh);
155  assert(pBoundaryConditions);
156  // Default to 2nd order quadrature. Our default basis functions are piecewise linear
157  // which means that we are integrating functions which in the worst case (mass matrix)
158  // are quadratic.
159  mpSurfaceQuadRule = new GaussianQuadratureRule<ELEMENT_DIM-1>(2);
160 }
161 
162 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
164 {
165  delete mpSurfaceQuadRule;
166 }
167 
168 
169 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
171 {
172  assert(this->mAssembleVector);
173 
174  HeartEventHandler::BeginEvent(HeartEventHandler::NEUMANN_BCS);
175 
176  // Loop over surface elements with non-zero Neumann boundary conditions
177  if (mpBoundaryConditions->AnyNonZeroNeumannConditions())
178  {
180  neumann_iterator = mpBoundaryConditions->BeginNeumann();
181 
182  c_vector<double, PROBLEM_DIM*ELEMENT_DIM> b_surf_elem;
183 
184  // Iterate over defined conditions
185  while (neumann_iterator != mpBoundaryConditions->EndNeumann())
186  {
187  const BoundaryElement<ELEMENT_DIM-1,SPACE_DIM>& r_surf_element = *(neumann_iterator->first);
188  AssembleOnSurfaceElement(r_surf_element, b_surf_elem);
189 
190  const size_t STENCIL_SIZE=PROBLEM_DIM*ELEMENT_DIM; // problem_dim*num_nodes_on_surface_element
191  unsigned p_indices[STENCIL_SIZE];
192  r_surf_element.GetStiffnessMatrixGlobalIndices(PROBLEM_DIM, p_indices);
193  PetscVecTools::AddMultipleValues<STENCIL_SIZE>(this->mVectorToAssemble, p_indices, b_surf_elem);
194  ++neumann_iterator;
195  }
196  }
197 
198  HeartEventHandler::EndEvent(HeartEventHandler::NEUMANN_BCS);
199 }
200 
201 
202 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
204  const BoundaryElement<ELEMENT_DIM-1,SPACE_DIM>& rSurfaceElement,
205  c_vector<double, PROBLEM_DIM*ELEMENT_DIM>& rBSurfElem)
206 {
207  c_vector<double, SPACE_DIM> weighted_direction;
208  double jacobian_determinant;
209  mpMesh->GetWeightedDirectionForBoundaryElement(rSurfaceElement.GetIndex(), weighted_direction, jacobian_determinant);
210 
211  rBSurfElem.clear();
212 
213  // Allocate memory for the basis function values
214  c_vector<double, ELEMENT_DIM> phi;
215 
216  // Loop over Gauss points
217  for (unsigned quad_index=0; quad_index<mpSurfaceQuadRule->GetNumQuadPoints(); quad_index++)
218  {
219  const ChastePoint<ELEMENT_DIM-1>& quad_point = mpSurfaceQuadRule->rGetQuadPoint(quad_index);
220 
221  SurfaceBasisFunction::ComputeBasisFunctions(quad_point, phi);
222 
224  // Interpolation: X only
226 
227  // The location of the Gauss point in the original element will be stored in x
228  ChastePoint<SPACE_DIM> x(0,0,0);
229 
230  this->ResetInterpolatedQuantities();
231  for (unsigned i=0; i<rSurfaceElement.GetNumNodes(); i++)
232  {
233  const c_vector<double, SPACE_DIM> node_loc = rSurfaceElement.GetNode(i)->rGetLocation();
234  x.rGetLocation() += phi(i)*node_loc;
235 
236  // Allow the concrete version of the assembler to interpolate any desired quantities
237  this->IncrementInterpolatedQuantities(phi(i), rSurfaceElement.GetNode(i));
238  }
239 
240 
242  // Create elemental contribution
244 
245  double wJ = jacobian_determinant * mpSurfaceQuadRule->GetWeight(quad_index);
247  noalias(rBSurfElem) += ComputeVectorSurfaceTerm(rSurfaceElement, phi, x) * wJ;
248  }
249 }
250 
251 #endif // ABSTRACTFESURFACENTEGRALASSEMBLER_HPP_
virtual void AssembleOnSurfaceElement(const BoundaryElement< ELEMENT_DIM-1, SPACE_DIM > &rSurfaceElement, c_vector< double, PROBLEM_DIM *ELEMENT_DIM > &rBSurfElem)
c_vector< double, DIM > & rGetLocation()
Definition: ChastePoint.cpp:76
AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * mpMesh
std::map< const BoundaryElement< ELEMENT_DIM-1, SPACE_DIM > *, const AbstractBoundaryCondition< SPACE_DIM > * >::const_iterator NeumannMapIterator
#define NEVER_REACHED
Definition: Exception.hpp:206
Node< SPACE_DIM > * GetNode(unsigned localIndex) const
BoundaryConditionsContainer< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM > * mpBoundaryConditions
GaussianQuadratureRule< ELEMENT_DIM-1 > * mpSurfaceQuadRule
LinearBasisFunction< ELEMENT_DIM-1 > SurfaceBasisFunction
unsigned GetNumNodes() const
void GetStiffnessMatrixGlobalIndices(unsigned problemDim, unsigned *pIndices) const
AbstractFeSurfaceIntegralAssembler(AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > *pMesh, BoundaryConditionsContainer< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM > *pBoundaryConditions)
void ResetBoundaryConditionsContainer(BoundaryConditionsContainer< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM > *pBoundaryConditions)
unsigned GetIndex() const
virtual c_vector< double, PROBLEM_DIM *ELEMENT_DIM > ComputeVectorSurfaceTerm(const BoundaryElement< ELEMENT_DIM-1, SPACE_DIM > &rSurfaceElement, c_vector< double, ELEMENT_DIM > &rPhi, ChastePoint< SPACE_DIM > &rX)