AbstractFeAssemblerInterface.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 
00029 #ifndef ABSTRACTFEASSEMBLERINTERFACE_HPP_
00030 #define ABSTRACTFEASSEMBLERINTERFACE_HPP_
00031 
00032 #include <cassert>
00033 #include "UblasCustomFunctions.hpp"
00034 #include "PetscTools.hpp"
00035 
00043 template <bool CAN_ASSEMBLE_VECTOR, bool CAN_ASSEMBLE_MATRIX>
00044 class AbstractFeAssemblerInterface  : boost::noncopyable
00045 {
00046 protected:
00048     Vec mVectorToAssemble;
00049 
00051     Mat mMatrixToAssemble;
00052 
00058     bool mAssembleMatrix;
00059 
00061     bool mAssembleVector;
00062 
00064     bool mZeroMatrixBeforeAssembly;
00065 
00067     bool mZeroVectorBeforeAssembly;
00068 
00070     PetscInt mOwnershipRangeLo;
00071 
00073     PetscInt mOwnershipRangeHi;
00074 
00082     virtual void DoAssemble()=0;
00083 
00084 public:
00085 
00089     AbstractFeAssemblerInterface();
00090 
00098     void SetMatrixToAssemble(Mat& rMatToAssemble, bool zeroMatrixBeforeAssembly=true);
00099 
00107     void SetVectorToAssemble(Vec& rVecToAssemble, bool zeroVectorBeforeAssembly);
00108 
00112     void Assemble()
00113     {
00114         mAssembleMatrix = CAN_ASSEMBLE_MATRIX;
00115         mAssembleVector = CAN_ASSEMBLE_VECTOR;
00116         DoAssemble();
00117     }
00118 
00122     void AssembleMatrix()
00123     {
00124         assert(CAN_ASSEMBLE_MATRIX);
00125         mAssembleMatrix = true;
00126         mAssembleVector = false;
00127         DoAssemble();
00128     }
00129 
00133     void AssembleVector()
00134     {
00135         assert(CAN_ASSEMBLE_VECTOR);
00136         mAssembleMatrix = false;
00137         mAssembleVector = true;
00138         DoAssemble();
00139     }
00140 
00144     virtual ~AbstractFeAssemblerInterface()
00145     {
00146     }
00147 };
00148 
00149 template <bool CAN_ASSEMBLE_VECTOR, bool CAN_ASSEMBLE_MATRIX>
00150 AbstractFeAssemblerInterface<CAN_ASSEMBLE_VECTOR, CAN_ASSEMBLE_MATRIX>::AbstractFeAssemblerInterface()
00151     : mVectorToAssemble(NULL),
00152       mMatrixToAssemble(NULL),
00153       mZeroMatrixBeforeAssembly(true),
00154       mZeroVectorBeforeAssembly(true)
00155 {
00156     assert(CAN_ASSEMBLE_VECTOR || CAN_ASSEMBLE_MATRIX);
00157 }
00158 
00159 template <bool CAN_ASSEMBLE_VECTOR, bool CAN_ASSEMBLE_MATRIX>
00160 void AbstractFeAssemblerInterface<CAN_ASSEMBLE_VECTOR, CAN_ASSEMBLE_MATRIX>::SetMatrixToAssemble(Mat& rMatToAssemble, bool zeroMatrixBeforeAssembly)
00161 {
00162     assert(rMatToAssemble);
00163     MatGetOwnershipRange(rMatToAssemble, &mOwnershipRangeLo, &mOwnershipRangeHi);
00164 
00165     mMatrixToAssemble = rMatToAssemble;
00166     mZeroMatrixBeforeAssembly = zeroMatrixBeforeAssembly;
00167 }
00168 
00169 template <bool CAN_ASSEMBLE_VECTOR, bool CAN_ASSEMBLE_MATRIX>
00170 void AbstractFeAssemblerInterface<CAN_ASSEMBLE_VECTOR, CAN_ASSEMBLE_MATRIX>::SetVectorToAssemble(Vec& rVecToAssemble, bool zeroVectorBeforeAssembly)
00171 {
00172     assert(rVecToAssemble);
00173     VecGetOwnershipRange(rVecToAssemble, &mOwnershipRangeLo, &mOwnershipRangeHi);
00174 
00175     mVectorToAssemble = rVecToAssemble;
00176     mZeroVectorBeforeAssembly = zeroVectorBeforeAssembly;
00177 }
00178 
00179 #endif // ABSTRACTFEASSEMBLERINTERFACE_HPP_
Generated on Thu Dec 22 13:00:17 2011 for Chaste by  doxygen 1.6.3