AbstractBoundaryConditionsContainerImplementation.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 
00030 #ifndef ABSTRACTBOUNDARYCONDITIONSCONTAINERIMPLEMENTATION_HPP_
00031 #define ABSTRACTBOUNDARYCONDITIONSCONTAINERIMPLEMENTATION_HPP_
00032 
00033 #include "AbstractBoundaryConditionsContainer.hpp"
00034 #include "PetscTools.hpp"
00035 
00036 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
00037 AbstractBoundaryConditionsContainer<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM>::AbstractBoundaryConditionsContainer(bool deleteConditions)
00038     : mHasDirichletBCs(false),
00039       mCheckedAndCommunicatedIfDirichletBcs(false),
00040       mDeleteConditions(deleteConditions)
00041 {
00042     for (unsigned index_of_unknown=0; index_of_unknown<PROBLEM_DIM; index_of_unknown++)
00043     {
00044         mpDirichletMap[index_of_unknown] =  new std::map< const Node<SPACE_DIM> *, const AbstractBoundaryCondition<SPACE_DIM>*, LessThanNode<SPACE_DIM> >;
00045     }
00046 }
00047 
00048 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
00049 AbstractBoundaryConditionsContainer<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM>::~AbstractBoundaryConditionsContainer()
00050 {
00051     DeleteDirichletBoundaryConditions();
00052 }
00053 
00054 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
00055 bool AbstractBoundaryConditionsContainer<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM>::HasDirichletBoundaryConditions()
00056 {
00057     if (!mCheckedAndCommunicatedIfDirichletBcs)
00058     {
00059         bool i_have_dirichlet=false;
00060         for (unsigned i=0; i<PROBLEM_DIM; i++)
00061         {
00062             if (!mpDirichletMap[i]->empty())
00063             {
00064                 i_have_dirichlet=true;
00065                 break;
00066             }
00067         }
00068         mHasDirichletBCs = PetscTools::ReplicateBool(i_have_dirichlet);
00069         mCheckedAndCommunicatedIfDirichletBcs = true;
00070     }
00071     return mHasDirichletBCs;
00072 }
00073 
00074 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
00075 void AbstractBoundaryConditionsContainer<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM>::DeleteDirichletBoundaryConditions(std::set<const AbstractBoundaryCondition<SPACE_DIM>*> alreadyDeletedConditions)
00076 {
00077     for (unsigned i=0; i<PROBLEM_DIM; i++)
00078     {
00079         if (mpDirichletMap[i])
00080         {
00081             mDirichIterator = mpDirichletMap[i]->begin();
00082             while (mDirichIterator != mpDirichletMap[i]->end() )
00083             {
00084                 if (alreadyDeletedConditions.count(mDirichIterator->second) == 0)
00085                 {
00086                     alreadyDeletedConditions.insert(mDirichIterator->second);
00087                     if (mDeleteConditions)
00088                     {
00089                         delete mDirichIterator->second;
00090                     }
00091                 }
00092                 mDirichIterator++;
00093             }
00094 
00095             delete(mpDirichletMap[i]);
00096             mpDirichletMap[i] = NULL;
00097         }
00098     }
00099 
00100     // Recommunicate that Dirichlet BCs have changed (next time we ask)
00101     ResetDirichletCommunication();
00102 }
00103 
00104 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
00105 double AbstractBoundaryConditionsContainer<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM>::GetDirichletBCValue(const Node<SPACE_DIM>* pBoundaryNode, unsigned indexOfUnknown)
00106 {
00107     assert(indexOfUnknown < PROBLEM_DIM);
00108     //assert(pBoundaryNode->IsBoundaryNode());
00109 
00110     mDirichIterator = mpDirichletMap[indexOfUnknown]->find(pBoundaryNode);
00111     assert(mDirichIterator != mpDirichletMap[indexOfUnknown]->end());
00112 
00113     return mDirichIterator->second->GetValue(pBoundaryNode->GetPoint());
00114 }
00115 
00116 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
00117 bool AbstractBoundaryConditionsContainer<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM>::HasDirichletBoundaryCondition(const Node<SPACE_DIM>* pNode, unsigned indexOfUnknown)
00118 {
00119     assert(indexOfUnknown < PROBLEM_DIM);
00120 
00121     this->mDirichIterator = this->mpDirichletMap[indexOfUnknown]->find(pNode);
00122 
00123     return (this->mDirichIterator != this->mpDirichletMap[indexOfUnknown]->end());
00124 }
00125 
00126 #endif /*ABSTRACTBOUNDARYCONDITIONSCONTAINERIMPLEMENTATION_HPP_*/

Generated on Mon Apr 18 11:35:36 2011 for Chaste by  doxygen 1.5.5