AbstractBoundaryConditionsContainerImplementation.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
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()
00038     : mHasDirichletBCs(false),
00039       mCheckedAndCommunicatedIfDirichletBcs(false)
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                     delete mDirichIterator->second;
00087                 }
00088                 mDirichIterator++;
00089             }
00090 
00091             delete(mpDirichletMap[i]);
00092             mpDirichletMap[i] = NULL;
00093         }
00094     }
00095 
00096     // Recommunicate that Dirichlet BCs have changed (next time we ask)
00097     ResetDirichletCommunication();
00098 }
00099 
00100 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
00101 double AbstractBoundaryConditionsContainer<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM>::GetDirichletBCValue(const Node<SPACE_DIM>* pBoundaryNode, unsigned indexOfUnknown)
00102 {
00103     assert(indexOfUnknown < PROBLEM_DIM);
00104     //assert(pBoundaryNode->IsBoundaryNode());
00105 
00106     mDirichIterator = mpDirichletMap[indexOfUnknown]->find(pBoundaryNode);
00107     assert(mDirichIterator != mpDirichletMap[indexOfUnknown]->end());
00108 
00109     return mDirichIterator->second->GetValue(pBoundaryNode->GetPoint());
00110 }
00111 
00112 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
00113 bool AbstractBoundaryConditionsContainer<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM>::HasDirichletBoundaryCondition(const Node<SPACE_DIM>* pNode, unsigned indexOfUnknown)
00114 {
00115     assert(indexOfUnknown < PROBLEM_DIM);
00116 
00117     this->mDirichIterator = this->mpDirichletMap[indexOfUnknown]->find(pNode);
00118 
00119     return (this->mDirichIterator != this->mpDirichletMap[indexOfUnknown]->end());
00120 }
00121 
00122 #endif /*ABSTRACTBOUNDARYCONDITIONSCONTAINERIMPLEMENTATION_HPP_*/

Generated on Mon Nov 1 12:35:24 2010 for Chaste by  doxygen 1.5.5