AbstractFeSurfaceIntegralAssembler.hpp

00001 /*
00002 
00003 Copyright (c) 2005-2015, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #ifndef ABSTRACTFESURFACENTEGRALASSEMBLER_HPP_
00037 #define ABSTRACTFESURFACENTEGRALASSEMBLER_HPP_
00038 
00039 #include "AbstractFeAssemblerCommon.hpp"
00040 #include "GaussianQuadratureRule.hpp"
00041 #include "BoundaryConditionsContainer.hpp"
00042 #include "PetscVecTools.hpp"
00043 #include "PetscMatTools.hpp"
00044 
00045 
00060 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
00061 class AbstractFeSurfaceIntegralAssembler : public AbstractFeAssemblerCommon<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM,true,false,NORMAL>
00062 {
00063 protected:
00065     AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>* mpMesh;
00066 
00068     BoundaryConditionsContainer<ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM>* mpBoundaryConditions;
00069 
00071     GaussianQuadratureRule<ELEMENT_DIM-1>* mpSurfaceQuadRule;
00072 
00074     typedef LinearBasisFunction<ELEMENT_DIM-1> SurfaceBasisFunction;
00075 
00089     virtual c_vector<double, PROBLEM_DIM*ELEMENT_DIM> ComputeVectorSurfaceTerm(
00090         const BoundaryElement<ELEMENT_DIM-1,SPACE_DIM>& rSurfaceElement,
00091         c_vector<double, ELEMENT_DIM>& rPhi,
00092         ChastePoint<SPACE_DIM>& rX)
00093     {
00094         // If this line is reached this means this method probably hasn't been over-ridden correctly in
00095         // the concrete class
00096         NEVER_REACHED;
00097         return zero_vector<double>(ELEMENT_DIM*PROBLEM_DIM);
00098     }
00099 
00109     virtual void AssembleOnSurfaceElement(const BoundaryElement<ELEMENT_DIM-1,SPACE_DIM>& rSurfaceElement,
00110                                           c_vector<double, PROBLEM_DIM*ELEMENT_DIM>& rBSurfElem);
00111 
00112 
00116     void DoAssemble();
00117 
00118 
00119 public:
00126     AbstractFeSurfaceIntegralAssembler(AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>* pMesh,
00127                                        BoundaryConditionsContainer<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM>* pBoundaryConditions);
00128 
00132     virtual ~AbstractFeSurfaceIntegralAssembler();
00133 
00138     void ResetBoundaryConditionsContainer(BoundaryConditionsContainer<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM>* pBoundaryConditions)
00139     {
00140         assert(pBoundaryConditions);
00141         this->mpBoundaryConditions = pBoundaryConditions;
00142     }
00143 };
00144 
00145 
00146 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
00147 AbstractFeSurfaceIntegralAssembler<ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM>::AbstractFeSurfaceIntegralAssembler(
00148             AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>* pMesh,
00149             BoundaryConditionsContainer<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM>* pBoundaryConditions)
00150     : AbstractFeAssemblerCommon<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM,true,false,NORMAL>(),
00151       mpMesh(pMesh),
00152       mpBoundaryConditions(pBoundaryConditions)
00153 {
00154     assert(pMesh);
00155     assert(pBoundaryConditions);
00156     // Default to 2nd order quadrature.  Our default basis functions are piecewise linear
00157     // which means that we are integrating functions which in the worst case (mass matrix)
00158     // are quadratic.
00159     mpSurfaceQuadRule = new GaussianQuadratureRule<ELEMENT_DIM-1>(2);
00160 }
00161 
00162 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
00163 AbstractFeSurfaceIntegralAssembler<ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM>::~AbstractFeSurfaceIntegralAssembler()
00164 {
00165     delete mpSurfaceQuadRule;
00166 }
00167 
00168 
00169 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
00170 void AbstractFeSurfaceIntegralAssembler<ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM>::DoAssemble()
00171 {
00172     assert(this->mAssembleVector);
00173 
00174     HeartEventHandler::BeginEvent(HeartEventHandler::NEUMANN_BCS);
00175 
00176     // Loop over surface elements with non-zero Neumann boundary conditions
00177     if (mpBoundaryConditions->AnyNonZeroNeumannConditions())
00178     {
00179         typename BoundaryConditionsContainer<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM>::NeumannMapIterator
00180             neumann_iterator = mpBoundaryConditions->BeginNeumann();
00181 
00182         c_vector<double, PROBLEM_DIM*ELEMENT_DIM> b_surf_elem;
00183 
00184         // Iterate over defined conditions
00185         while (neumann_iterator != mpBoundaryConditions->EndNeumann())
00186         {
00187             const BoundaryElement<ELEMENT_DIM-1,SPACE_DIM>& r_surf_element = *(neumann_iterator->first);
00188             AssembleOnSurfaceElement(r_surf_element, b_surf_elem);
00189 
00190             const size_t STENCIL_SIZE=PROBLEM_DIM*ELEMENT_DIM; // problem_dim*num_nodes_on_surface_element
00191             unsigned p_indices[STENCIL_SIZE];
00192             r_surf_element.GetStiffnessMatrixGlobalIndices(PROBLEM_DIM, p_indices);
00193             PetscVecTools::AddMultipleValues<STENCIL_SIZE>(this->mVectorToAssemble, p_indices, b_surf_elem);
00194             ++neumann_iterator;
00195         }
00196     }
00197 
00198     HeartEventHandler::EndEvent(HeartEventHandler::NEUMANN_BCS);
00199 }
00200 
00201 
00202 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
00203 void AbstractFeSurfaceIntegralAssembler<ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM>::AssembleOnSurfaceElement(
00204             const BoundaryElement<ELEMENT_DIM-1,SPACE_DIM>& rSurfaceElement,
00205             c_vector<double, PROBLEM_DIM*ELEMENT_DIM>& rBSurfElem)
00206 {
00207     c_vector<double, SPACE_DIM> weighted_direction;
00208     double jacobian_determinant;
00209     mpMesh->GetWeightedDirectionForBoundaryElement(rSurfaceElement.GetIndex(), weighted_direction, jacobian_determinant);
00210 
00211     rBSurfElem.clear();
00212 
00213     // Allocate memory for the basis function values
00214     c_vector<double, ELEMENT_DIM>  phi;
00215 
00216     // Loop over Gauss points
00217     for (unsigned quad_index=0; quad_index<mpSurfaceQuadRule->GetNumQuadPoints(); quad_index++)
00218     {
00219         const ChastePoint<ELEMENT_DIM-1>& quad_point = mpSurfaceQuadRule->rGetQuadPoint(quad_index);
00220 
00221         SurfaceBasisFunction::ComputeBasisFunctions(quad_point, phi);
00222 
00224         // Interpolation: X only
00226 
00227         // The location of the Gauss point in the original element will be stored in x
00228         ChastePoint<SPACE_DIM> x(0,0,0);
00229 
00230         this->ResetInterpolatedQuantities();
00231         for (unsigned i=0; i<rSurfaceElement.GetNumNodes(); i++)
00232         {
00233             const c_vector<double, SPACE_DIM> node_loc = rSurfaceElement.GetNode(i)->rGetLocation();
00234             x.rGetLocation() += phi(i)*node_loc;
00235 
00236             // Allow the concrete version of the assembler to interpolate any desired quantities
00237             this->IncrementInterpolatedQuantities(phi(i), rSurfaceElement.GetNode(i));
00238         }
00239 
00240 
00242         // Create elemental contribution
00244 
00245         double wJ = jacobian_determinant * mpSurfaceQuadRule->GetWeight(quad_index);
00247         noalias(rBSurfElem) += ComputeVectorSurfaceTerm(rSurfaceElement, phi, x) * wJ;
00248     }
00249 }
00250 
00251 #endif // ABSTRACTFESURFACENTEGRALASSEMBLER_HPP_

Generated by  doxygen 1.6.2