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