SimpleLinearEllipticAssembler.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 #ifndef _SIMPLELINEARELLIPTICASSEMBLER_HPP_
00029 #define _SIMPLELINEARELLIPTICASSEMBLER_HPP_
00030 
00031 
00032 #include <vector>
00033 #include <petscvec.h>
00034 
00035 #include "LinearSystem.hpp"
00036 #include "AbstractLinearEllipticPde.hpp"
00037 #include "AbstractLinearAssembler.hpp"
00038 #include "BoundaryConditionsContainer.hpp"
00039 #include "GaussianQuadratureRule.hpp"
00040 
00041 #include <boost/mpl/void.hpp>
00042 #include <boost/mpl/if.hpp>
00043 
00049 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, class CONCRETE = boost::mpl::void_>
00050 class SimpleLinearEllipticAssembler : public AbstractLinearAssembler<ELEMENT_DIM, SPACE_DIM, 1, true, SimpleLinearEllipticAssembler<ELEMENT_DIM, SPACE_DIM, CONCRETE> >
00051 {
00052 public:
00053     static const unsigned E_DIM = ELEMENT_DIM;
00054     static const unsigned S_DIM = SPACE_DIM;
00055     static const unsigned P_DIM = 1u;
00056 
00057     friend class TestSimpleLinearEllipticAssembler;
00058 
00059     typedef SimpleLinearEllipticAssembler<ELEMENT_DIM, SPACE_DIM, CONCRETE> SelfType;
00060     typedef AbstractLinearAssembler<ELEMENT_DIM, SPACE_DIM, 1, true, SelfType> BaseClassType;
00062     friend class AbstractStaticAssembler<ELEMENT_DIM, SPACE_DIM, 1, true, SelfType>;
00063 
00064 protected:
00065     AbstractLinearEllipticPde<ELEMENT_DIM,SPACE_DIM>* mpEllipticPde;
00066 
00067 protected:
00073     virtual c_matrix<double,1*(ELEMENT_DIM+1),1*(ELEMENT_DIM+1)> ComputeMatrixTerm(
00074         c_vector<double, ELEMENT_DIM+1> &rPhi,
00075         c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1> &rGradPhi,
00076         ChastePoint<SPACE_DIM> &rX,
00077         c_vector<double,1> &u,
00078         c_matrix<double,1,SPACE_DIM> &rGradU,
00079         Element<ELEMENT_DIM,SPACE_DIM>* pElement)
00080     {
00081         c_matrix<double, ELEMENT_DIM, ELEMENT_DIM> pde_diffusion_term = mpEllipticPde->ComputeDiffusionTerm(rX);
00082 
00083         // if statement just saves computing phi*phi^T if it is to be multiplied by zero
00084         if(mpEllipticPde->ComputeLinearInUCoeffInSourceTerm(rX,pElement)!=0)
00085         {
00086             return   prod( trans(rGradPhi), c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1>(prod(pde_diffusion_term, rGradPhi)) )
00087                    - mpEllipticPde->ComputeLinearInUCoeffInSourceTerm(rX,pElement)*outer_prod(rPhi,rPhi);
00088         }
00089         else
00090         {
00091             return   prod( trans(rGradPhi), c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1>(prod(pde_diffusion_term, rGradPhi)) );
00092         }
00093     }
00094 
00099     virtual c_vector<double,1*(ELEMENT_DIM+1)> ComputeVectorTerm(
00100         c_vector<double, ELEMENT_DIM+1> &rPhi,
00101         c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1> &rGradPhi,
00102         ChastePoint<SPACE_DIM> &rX,
00103         c_vector<double,1> &u,
00104         c_matrix<double,1,SPACE_DIM> &rGradU,
00105         Element<ELEMENT_DIM,SPACE_DIM>* pElement)
00106     {
00107         return mpEllipticPde->ComputeConstantInUSourceTerm(rX) * rPhi;
00108     }
00109 
00110 
00111 
00112     virtual c_vector<double, ELEMENT_DIM> ComputeVectorSurfaceTerm(const BoundaryElement<ELEMENT_DIM-1,SPACE_DIM> &rSurfaceElement,
00113             c_vector<double, ELEMENT_DIM> &rPhi,
00114             ChastePoint<SPACE_DIM> &rX )
00115     {
00116         // D_times_gradu_dot_n = [D grad(u)].n, D=diffusion matrix
00117         double D_times_gradu_dot_n = this->mpBoundaryConditions->GetNeumannBCValue(&rSurfaceElement, rX);
00118         return rPhi * D_times_gradu_dot_n;
00119     }
00120 
00121 
00122 
00123 public:
00127     SimpleLinearEllipticAssembler(AbstractMesh<ELEMENT_DIM,SPACE_DIM>* pMesh,
00128                                   AbstractLinearEllipticPde<ELEMENT_DIM,SPACE_DIM>* pPde,
00129                                   BoundaryConditionsContainer<ELEMENT_DIM,SPACE_DIM,1>* pBoundaryConditions,
00130                                   unsigned numQuadPoints = 2) :
00131             AbstractAssembler<ELEMENT_DIM,SPACE_DIM,1>(),
00132             BaseClassType(numQuadPoints)
00133     {
00134         // note - we don't check any of these are NULL here (that is done in Solve() instead),
00135         // to allow the user or a subclass to set any of these later
00136         mpEllipticPde = pPde;
00137         this->SetMesh(pMesh);
00138         this->SetBoundaryConditionsContainer(pBoundaryConditions);
00139     }
00140 
00144     void PrepareForSolve()
00145     {
00146         BaseClassType::PrepareForSolve();
00147         assert(mpEllipticPde != NULL);
00148     }
00149 };
00150 
00152 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, class CONCRETE>
00153 struct AssemblerTraits<SimpleLinearEllipticAssembler<ELEMENT_DIM, SPACE_DIM, CONCRETE> >
00154 {
00155     typedef typename boost::mpl::if_<boost::mpl::is_void_<CONCRETE>,
00156                                      SimpleLinearEllipticAssembler<ELEMENT_DIM, SPACE_DIM, CONCRETE>,
00157                                      typename AssemblerTraits<CONCRETE>::CVT_CLS>::type
00158             CVT_CLS;
00159     typedef typename boost::mpl::if_<boost::mpl::is_void_<CONCRETE>,
00160                                      SimpleLinearEllipticAssembler<ELEMENT_DIM, SPACE_DIM, CONCRETE>,
00161                                      typename AssemblerTraits<CONCRETE>::CMT_CLS>::type
00162             CMT_CLS;
00164     typedef typename boost::mpl::if_<boost::mpl::is_void_<CONCRETE>,
00165                      AbstractAssembler<ELEMENT_DIM, SPACE_DIM, 1u>,
00166                      typename AssemblerTraits<CONCRETE>::CMT_CLS>::type
00167             INTERPOLATE_CLS;
00168 };
00169 
00170 #endif //_SIMPLELINEARELLIPTICASSEMBLER_HPP_

Generated on Wed Mar 18 12:51:56 2009 for Chaste by  doxygen 1.5.5