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