AbstractBoundaryConditionsContainerImplementation.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
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