From 9ce18f57eec131d0325b8e581de38b9e530a8f91 Mon Sep 17 00:00:00 2001 From: Thomas Witkowski <thomas.witkowski@gmx.de> Date: Thu, 23 Oct 2008 13:58:06 +0000 Subject: [PATCH] * More bugfixes for SolutionDataStorage support --- AMDiS/src/DOFAdmin.h | 6 ++-- AMDiS/src/DOFVector.hh | 2 ++ AMDiS/src/Element.cc | 47 ++++++++++++++++++++++++++++++-- AMDiS/src/Element.h | 4 ++- AMDiS/src/Mesh.cc | 27 ++++++++++++++---- AMDiS/src/Serializable.h | 6 ++-- AMDiS/src/SolutionDataStorage.h | 19 ++++++------- AMDiS/src/SolutionDataStorage.hh | 30 +++++++++++++------- AMDiS/src/SystemVector.h | 8 ++++-- 9 files changed, 112 insertions(+), 37 deletions(-) diff --git a/AMDiS/src/DOFAdmin.h b/AMDiS/src/DOFAdmin.h index 6462be44..d3bc87f6 100644 --- a/AMDiS/src/DOFAdmin.h +++ b/AMDiS/src/DOFAdmin.h @@ -82,7 +82,7 @@ namespace AMDiS { /** \brief * constructor */ - DOFAdmin(Mesh* m,std::string aName); + DOFAdmin(Mesh* m, std::string aName); /** \brief * copy constructor @@ -92,7 +92,7 @@ namespace AMDiS { /** \brief * destructor */ - virtual ~DOFAdmin(); + ~DOFAdmin(); /** \brief * Enlarges the number of DOFs that can be managed at least to minsize by @@ -115,7 +115,7 @@ namespace AMDiS { */ inline bool operator!=(const DOFAdmin& ad) const { return !(ad==*this); - }; + } /** \brief * Adds a DOFIndexedBase object to the DOFAdmin. This object will be diff --git a/AMDiS/src/DOFVector.hh b/AMDiS/src/DOFVector.hh index 9abc9918..5a920133 100644 --- a/AMDiS/src/DOFVector.hh +++ b/AMDiS/src/DOFVector.hh @@ -82,6 +82,8 @@ namespace AMDiS { if (this->boundaryManager) { DELETE this->boundaryManager; } + + vec.clear(); } template<typename T> diff --git a/AMDiS/src/Element.cc b/AMDiS/src/Element.cc index a3eb2222..047f2b40 100644 --- a/AMDiS/src/Element.cc +++ b/AMDiS/src/Element.cc @@ -53,17 +53,58 @@ namespace AMDiS { // call destructor through Mesh::freeElement !!! Element::~Element() - { - if (child[0]) + { + if (child[0]) { DELETE child[0]; - if (child[1]) + } + if (child[1]) { DELETE child[1]; + } if (newCoord) { DELETE newCoord; } } + void Element::deleteElementDOFs() + { + int dim = mesh->getDim(); + int j = 0; + + for (int pos = 0; pos <= dim; pos++) { + GeoIndex position = INDEX_OF_DIM(pos, dim); + int ndof = 0; + + for (int i = 0; i < mesh->getNumberOfDOFAdmin(); i++) { + ndof += mesh->getDOFAdmin(i).getNumberOfDOFs(position); + } + + if (ndof > 0) { + for (int i = 0; i < mesh->getGeo(position); i++) { + if (dof[j] != NULL) { + if (Mesh::serializedDOFs.count(dof[j][0]) == 0) { + // std::cout << "FREE INNER: " << ndof << std::endl; + FREE_MEMORY(dof[j], DegreeOfFreedom, ndof); + Mesh::serializedDOFs[dof[j][0]] = NULL; + } + } + + j++; + } + } + } + + // std::cout << "FREE OUTER: " << mesh->getNumberOfNodes() << std::endl; + FREE_MEMORY(dof, DegreeOfFreedom*, mesh->getNumberOfNodes()); + + if (child[0]) { + child[0]->deleteElementDOFs(); + } + if (child[1]) { + child[1]->deleteElementDOFs(); + } + } + Element* Element::cloneWithDOFs() { Element *el; diff --git a/AMDiS/src/Element.h b/AMDiS/src/Element.h index 91426b22..ab62a7b4 100644 --- a/AMDiS/src/Element.h +++ b/AMDiS/src/Element.h @@ -84,7 +84,7 @@ namespace AMDiS { /** \brief * private standard constructor because an Element must know his Mesh */ - Element() {}; + Element() {} public: /** \brief * constructs an Element which belongs to Mesh @@ -101,6 +101,8 @@ namespace AMDiS { */ virtual ~Element(); + void deleteElementDOFs(); + /** \brief * Clone this Element and return a reference to it. Because also the DOFs * are cloned, \ref Mesh::serializedDOfs must be used. diff --git a/AMDiS/src/Mesh.cc b/AMDiS/src/Mesh.cc index 517c01c7..8d9e8c70 100644 --- a/AMDiS/src/Mesh.cc +++ b/AMDiS/src/Mesh.cc @@ -92,6 +92,7 @@ namespace AMDiS { elementDataPrototype(NULL), elementIndex(-1), initialized(false), + macroFileInfo(NULL), final_lambda(dimension, DEFAULT_VALUE, 0.0) { @@ -118,7 +119,22 @@ namespace AMDiS { } Mesh::~Mesh() - {} + { + serializedDOFs.empty(); + + for (std::deque<MacroElement*>::const_iterator it = macroElements.begin(); + it != macroElements.end(); + ++it) { + (*it)->getElement()->deleteElementDOFs(); + DELETE *it; + } + + serializedDOFs.empty(); + + if (macroFileInfo) { + DELETE macroFileInfo; + } + } Mesh& Mesh::operator=(const Mesh& m) { @@ -540,10 +556,10 @@ namespace AMDiS { bool Mesh::findElInfoAtPoint(const WorldVector<double>& xy, ElInfo *el_info, - DimVec<double>& bary, - const MacroElement *start_mel, + DimVec<double>& bary, + const MacroElement *start_mel, const WorldVector<double> *xy0, - double *sp) + double *sp) { static const MacroElement *mel = NULL; DimVec<double> lambda(dim, NO_INIT); @@ -637,8 +653,9 @@ namespace AMDiS { MSG("outside finest level on el %d: s=%.3e\n", el->getIndex(), s); return(false); /* ??? */ + } else { + return(false); } - else return(false); } } diff --git a/AMDiS/src/Serializable.h b/AMDiS/src/Serializable.h index ef8250e9..1968c45a 100644 --- a/AMDiS/src/Serializable.h +++ b/AMDiS/src/Serializable.h @@ -52,9 +52,11 @@ namespace AMDiS { /** \brief * Returns the type name for this serializable object. */ - virtual std::string getTypeName() const { return ""; }; + virtual std::string getTypeName() const { + return ""; + } - virtual ~Serializable() {}; + virtual ~Serializable() {} }; } diff --git a/AMDiS/src/SolutionDataStorage.h b/AMDiS/src/SolutionDataStorage.h index 21fafca6..3fb25ee5 100644 --- a/AMDiS/src/SolutionDataStorage.h +++ b/AMDiS/src/SolutionDataStorage.h @@ -66,10 +66,6 @@ namespace AMDiS { typename SolutionHelper<T>::type feSpace, double *timestep); - T* getSolution() { - return solutions[0]; - } - /** \brief * Deletes all pointers and empties all internal vectors. */ @@ -87,19 +83,20 @@ namespace AMDiS { protected: /** \brief - * Auxiliary function for deleting either a single fe space, or a - * vector of fe spaces. + * Deletes the fe space and all it content, i.e., also the dof admin, + * mesh, etc. */ - void deleteFeSpace(FiniteElemSpace* feSpace) { - DELETE feSpace; - } + void deleteFeSpace(FiniteElemSpace* feSpace); + /** \brief + * Deletes a list of fe spaces. + */ void deleteFeSpace(std::vector<FiniteElemSpace*> feSpaces) { for (int i = 0; i < static_cast<int>(feSpaces.size()); i++) { - DELETE feSpaces[i]; + deleteFeSpace(feSpaces[i]); } - feSpaces.empty(); + feSpaces.clear(); } int addMemoryUsage(FiniteElemSpace* feSpace) { diff --git a/AMDiS/src/SolutionDataStorage.hh b/AMDiS/src/SolutionDataStorage.hh index ec15a588..805b6de5 100644 --- a/AMDiS/src/SolutionDataStorage.hh +++ b/AMDiS/src/SolutionDataStorage.hh @@ -23,7 +23,6 @@ namespace AMDiS { template<typename T> SolutionDataStorage<T>::~SolutionDataStorage() { - clear(); } template<typename T> @@ -53,7 +52,7 @@ namespace AMDiS { timestamps.push_back(timestamp); lastPos++; - memoryUsage += solution->calcMemoryUsage(); + // memoryUsage += solution->calcMemoryUsage(); } template<typename T> @@ -112,25 +111,36 @@ namespace AMDiS { template<typename T> void SolutionDataStorage<T>::clear() { - for (int i = 0; i < static_cast<int>(solutions.size()); i++) { - DELETE solutions[i]; + for (int i = 1; i < static_cast<int>(solutions.size()); i++) { + DELETE solutions[i]; } - std::cout << "MARK 1" << std::endl; - if (!fixedFESpace) { for (int i = 0; i < static_cast<int>(feSpaces.size()); i++) { deleteFeSpace(feSpaces[i]); } } - std::cout << "MARK 2" << std::endl; - solutions.clear(); feSpaces.clear(); timestamps.clear(); - lastPos = -1; + lastPos = -1; + } + + template<typename T> + void SolutionDataStorage<T>::deleteFeSpace(FiniteElemSpace *feSpace) + { + if (feSpace) { + if (feSpace->getMesh()) { + DELETE feSpace->getMesh(); + } + if (feSpace->getAdmin()) { + DELETE feSpace->getAdmin(); + } + + DELETE feSpace; + } } - + } diff --git a/AMDiS/src/SystemVector.h b/AMDiS/src/SystemVector.h index b0286131..9f056c0f 100644 --- a/AMDiS/src/SystemVector.h +++ b/AMDiS/src/SystemVector.h @@ -140,8 +140,12 @@ namespace AMDiS { } } - virtual ~SystemVector() - {} + ~SystemVector() + { + for (int i = 0; i < vectors.getSize(); i++) { + DELETE vectors[i]; + } + } void createNewDOFVectors(std::string name) { -- GitLab