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
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
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
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