00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <DegreeOfFreedomSetManager.hpp>
00021
00022 #include <ScalarDiscretizationTypeBase.hpp>
00023 #include <ScalarDiscretizationTypeSpectral.hpp>
00024
00025 #include <ScalarDegreeOfFreedomPositionsSet.hpp>
00026 #include <StreamCenter.hpp>
00027
00028 #include <Structured3DMesh.hpp>
00029 #include <MeshOfTetrahedra.hpp>
00030
00031 #include <Mesh.hpp>
00032
00033
00034 class DegreeOfFreedomSetManager::Internal
00035 {
00036 private:
00037 typedef std::string DiscretizationLabel;
00038
00039 typedef
00040 std::map<std::pair<const Mesh*, DiscretizationLabel>,
00041 std::pair<size_t, ScalarDegreeOfFreedomPositionsSet*> >
00042 MeshesDOFPositionsCorrespondance;
00043
00044 MeshesDOFPositionsCorrespondance __meshesDOFPositions;
00045
00046 public:
00047 ConstReferenceCounting <ScalarDegreeOfFreedomPositionsSet>
00048 getDOFPositionsSet(const Mesh& mesh,
00049 const ScalarDiscretizationTypeBase& discretizationType)
00050 {
00051 DiscretizationLabel label = ScalarDiscretizationTypeBase::name(discretizationType);
00052
00053 switch (discretizationType.type()) {
00054 case ScalarDiscretizationTypeBase::spectralLegendre: {
00055 const ScalarDiscretizationTypeSpectral& spectralDiscretizationType
00056 = dynamic_cast<const ScalarDiscretizationTypeSpectral&>(discretizationType);
00057 label += "-"+stringify(spectralDiscretizationType.degrees());
00058 break;
00059 }
00060 default: {
00061 }
00062 }
00063
00064 MeshesDOFPositionsCorrespondance::iterator
00065 i = __meshesDOFPositions.find(std::make_pair(&mesh,label));
00066
00067 if (i != __meshesDOFPositions.end()) {
00068 (*i).second.first++;
00069 return (*i).second.second;
00070 } else {
00071 ScalarDegreeOfFreedomPositionsSet* dof
00072 = new ScalarDegreeOfFreedomPositionsSet(discretizationType,mesh);
00073
00074 __meshesDOFPositions[std::make_pair(&mesh, label)]
00075 = std::make_pair(1,dof);
00076 return dof;
00077 }
00078 }
00079
00080 void unsubscribe(ConstReferenceCounting<ScalarDegreeOfFreedomPositionsSet> dofSet)
00081 {
00082 for (MeshesDOFPositionsCorrespondance::iterator i
00083 = __meshesDOFPositions.begin();
00084 i != __meshesDOFPositions.end(); ++i) {
00085 if ((*i).second.second == dofSet) {
00086 (*i).second.first--;
00087 if ((*i).second.first == 0) {
00088 __meshesDOFPositions.erase(i);
00089 }
00090 return;
00091 }
00092 }
00093 throw ErrorHandler(__FILE__,__LINE__,
00094 "DOF Set not found!",
00095 ErrorHandler::unexpected);
00096
00097 }
00098
00099 Internal()
00100 {
00101 ;
00102 }
00103
00104 ~Internal()
00105 {
00106 if (__meshesDOFPositions.size() > 0) {
00107 fferr(1) << __FILE__ << ':' << __LINE__
00108 << ":warning: degrees of freedom set manager is not empty!\n";
00109 }
00110 }
00111 };
00112
00113
00114 ConstReferenceCounting<ScalarDegreeOfFreedomPositionsSet>
00115 DegreeOfFreedomSetManager::
00116 getDOFPositionsSet(const Mesh& mesh,
00117 const ScalarDiscretizationTypeBase& discretizationType)
00118 {
00119 return __internal->getDOFPositionsSet(mesh, discretizationType);
00120 }
00121
00122 void DegreeOfFreedomSetManager::
00123 unsubscribe(ConstReferenceCounting<ScalarDegreeOfFreedomPositionsSet> dofSet)
00124 {
00125 __internal->unsubscribe(dofSet);
00126 }
00127
00128
00129 DegreeOfFreedomSetManager::
00130 DegreeOfFreedomSetManager()
00131 {
00132 __internal = new Internal();
00133 }
00134
00135 DegreeOfFreedomSetManager::
00136 ~DegreeOfFreedomSetManager()
00137 {
00138 delete __internal;
00139 }