diff --git a/AMDiS/src/DOFAdmin.cc b/AMDiS/src/DOFAdmin.cc index c8cc47b655eee2845c2858a8c9d811dd35c57494..792902845782a5baab98d8f006c73acb69797585 100755 --- a/AMDiS/src/DOFAdmin.cc +++ b/AMDiS/src/DOFAdmin.cc @@ -172,8 +172,8 @@ namespace AMDiS { ::std::list<DOFIndexedBase*>::iterator di; ::std::list<DOFIndexedBase*>::iterator end = dofIndexedList.end(); - for(di = dofIndexedList.begin(); di != end; ++di) { - if((*di)->getSize() < newval) { + for (di = dofIndexedList.begin(); di != end; ++di) { + if ((*di)->getSize() < newval) { (*di)->resize(newval); } } @@ -183,41 +183,44 @@ namespace AMDiS { FUNCNAME("DOFAdmin::addDOFIndexed"); TEST_EXIT(dofIndexed)("no dofIndexed\n"); - if(dofIndexed->getSize() < size) { + if (dofIndexed->getSize() < size) { dofIndexed->resize(size); } - + dofIndexedList.push_back(dofIndexed); } void DOFAdmin::removeDOFIndexed(DOFIndexedBase* dofIndexed) { - FUNCNAME("DOFAdmin::removeDOFIndexed"); + FUNCNAME("DOFAdmin::removeDOFIndexed()"); + ::std::list<DOFIndexedBase*>::iterator it; ::std::list<DOFIndexedBase*>::iterator end = dofIndexedList.end(); - for(it=dofIndexedList.begin(); it != end; ++it) { - if(*it == dofIndexed) { + for (it = dofIndexedList.begin(); it != end; ++it) { + if (*it == dofIndexed) { dofIndexedList.erase(it); return; } } + ERROR("DOFIndexed not in list\n"); } void DOFAdmin::addDOFContainer(DOFContainer* cont) { - FUNCNAME("DOFAdmin::addDOFContainer"); + FUNCNAME("DOFAdmin::addDOFContainer()"); TEST_EXIT(cont)("no container\n"); dofContainerList.push_back(cont); } void DOFAdmin::removeDOFContainer(DOFContainer* cont) { - FUNCNAME("DOFAdmin::removeDOFContainer"); + FUNCNAME("DOFAdmin::removeDOFContainer()"); + ::std::list<DOFContainer*>::iterator it; ::std::list<DOFContainer*>::iterator end = dofContainerList.end(); - for(it=dofContainerList.begin(); it != end; ++it) { - if(*it == cont) { + for (it = dofContainerList.begin(); it != end; ++it) { + if (*it == cont) { dofContainerList.erase(it); return; } diff --git a/AMDiS/src/DOFAdmin.h b/AMDiS/src/DOFAdmin.h index 51a5ae689dcdaad29bc67fa5e36dd4af2d681c80..92932bc7c8e1ad4126b0c4c07e43e319d4f86bd6 100644 --- a/AMDiS/src/DOFAdmin.h +++ b/AMDiS/src/DOFAdmin.h @@ -112,7 +112,9 @@ namespace AMDiS { /** \brief * Compares two DOFAdmins by their names. */ - inline bool operator!=(const DOFAdmin& ad) const {return !(ad==*this);}; + 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.h b/AMDiS/src/DOFVector.h index fe044c5fb00b1d42d7f101113b167ff6a4bfb301..ea2b9376adace17e9dfd2a4dcdb04415fbc929be 100644 --- a/AMDiS/src/DOFVector.h +++ b/AMDiS/src/DOFVector.h @@ -315,12 +315,16 @@ namespace AMDiS { /** \brief * Returns iterator to the begin of \ref vec */ - typename ::std::vector<T>::iterator begin() { return vec.begin(); }; + typename ::std::vector<T>::iterator begin() { + return vec.begin(); + }; /** \brief * Returns iterator to the end of \ref vec */ - typename ::std::vector<T>::iterator end() { return vec.end(); }; + typename ::std::vector<T>::iterator end() { + return vec.end(); + }; /** \brief * Used by DOFAdmin to compress this DOFVector. Implementation of @@ -332,7 +336,9 @@ namespace AMDiS { /** \brief * Sets \ref refineInter to b */ - inline void refineInterpol(bool b) { refineInter = b; }; + inline void refineInterpol(bool b) { + refineInter = b; + }; /** \brief * Sets \ref coarsenOperation to op @@ -375,12 +381,16 @@ namespace AMDiS { /** \brief * Returns size of \ref vec */ - inline int getSize() const { return vec.size();}; + inline int getSize() const { + return vec.size(); + }; /** \brief * Returns used size of the vector. */ - inline int getUsedSize() const { return feSpace->getAdmin()->getUsedSize(); }; + inline int getUsedSize() const { + return feSpace->getAdmin()->getUsedSize(); + }; /** \brief * Resizes \ref vec to n @@ -409,7 +419,9 @@ namespace AMDiS { return vec[i]; }; - inline int getSize() { return vec.size(); }; + inline int getSize() { + return vec.size(); + }; /** \brief * Returns \ref vec[i] diff --git a/AMDiS/src/DOFVector.hh b/AMDiS/src/DOFVector.hh index 274d3eb8899a2523163b6c53f6cefb2d72e383a4..77e9a26a863a243575c1b1865fe17524be694c5a 100644 --- a/AMDiS/src/DOFVector.hh +++ b/AMDiS/src/DOFVector.hh @@ -25,17 +25,16 @@ namespace AMDiS { const BoundaryType *bound, bool add) { - FUNCNAME("DOFVector::addElementVector"); - DegreeOfFreedom i, irow; + FUNCNAME("DOFVector::addElementVector()"); int n_row = elVec.getSize(); - for (i = 0; i < n_row; i++) { + for (DegreeOfFreedom i = 0; i < n_row; i++) { BoundaryCondition *condition = bound ? this->getBoundaryManager()->getBoundaryCondition(bound[i]) : NULL; if(!(condition && condition->isDirichlet())) { - irow = elVec.dofIndices[i]; + DegreeOfFreedom irow = elVec.dofIndices[i]; (*this)[irow] = (add ? (*this)[irow] : 0.0); (*this)[irow] += factor * elVec[i]; } @@ -46,7 +45,8 @@ namespace AMDiS { DOFVector<T>::DOFVector(const FiniteElemSpace* f,::std::string n) : DOFVectorBase<T>(f, n), //elementVector(NULL), - refineInter(false), coarsenOperation(NO_OPERATION) + refineInter(false), + coarsenOperation(NO_OPERATION) { init(f, n); } @@ -56,7 +56,7 @@ namespace AMDiS { { name = n; feSpace = f; - if(feSpace && feSpace->getAdmin()) { + if (feSpace && feSpace->getAdmin()) { (feSpace->getAdmin())->addDOFIndexed(this); } this->boundaryManager = NEW BoundaryManager; @@ -65,7 +65,7 @@ namespace AMDiS { template<typename T> DOFVector<T>::~DOFVector() { - if(feSpace && feSpace->getAdmin()) { + if (feSpace && feSpace->getAdmin()) { (feSpace->getAdmin())->removeDOFIndexed(this); } diff --git a/AMDiS/src/DataCollector.cc b/AMDiS/src/DataCollector.cc index cf5b8a41f8843e3a0d227130d966fa67881aab89..2f37746479a3ab681a118499afb7f7a4a1ac681e 100644 --- a/AMDiS/src/DataCollector.cc +++ b/AMDiS/src/DataCollector.cc @@ -17,7 +17,7 @@ namespace AMDiS { TEST_EXIT(feSpace)("no feSpace\n"); TEST_EXIT(values)("no value Vector\n"); - + // === get mesh === mesh_ = feSpace->getMesh(); @@ -26,7 +26,6 @@ namespace AMDiS { // === create vertex info vector === vertexInfos_ = NEW DOFVector< ::std::list<VertexInfo> >(feSpace, "vertex infos"); - interpPointInd_ = NEW DOFVector<int>(feSpace, "interpolation point indices"); dofCoords_ = NEW DOFVector< ::std::list<WorldVector<double> > >(feSpace, "dof coords"); diff --git a/AMDiS/src/FileWriter.cc b/AMDiS/src/FileWriter.cc index cc8317bc5d4738d284ea3183702bb175ff58d430..aef11b2f10f1fd1b23d1c9dbda900df8bf71bacc 100644 --- a/AMDiS/src/FileWriter.cc +++ b/AMDiS/src/FileWriter.cc @@ -18,21 +18,11 @@ namespace AMDiS { Mesh *mesh_, DOFVector<double> *vec) : name(name_), - tecplotExt(".tec"), - amdisMeshExt(".mesh"), - amdisDataExt(".dat"), - paraViewFileExt(".vtu"), - periodicFileExt(".per"), - writeTecPlotFormat(0), - writeAMDiSFormat(0), - writeParaViewFormat(0), - writePeriodicFormat(0), - appendIndex(0), - indexLength(5), - indexDecimals(3), - tsModulo(1), mesh(mesh_) { + FUNCNAME("FileWriter::FileWriter()"); + + initialize(); readParameters(); feSpace = vec->getFESpace(); @@ -41,27 +31,16 @@ namespace AMDiS { solutionVecs_[0] = vec; } + FileWriter::FileWriter(const ::std::string &name_, Mesh *mesh_, ::std::vector< DOFVector<double>* > vecs) : name(name_), - tecplotExt(".tec"), - amdisMeshExt(".mesh"), - amdisDataExt(".dat"), - paraViewFileExt(".vtu"), - periodicFileExt(".per"), - writeTecPlotFormat(0), - writeAMDiSFormat(0), - writeParaViewFormat(0), - writePeriodicFormat(0), - appendIndex(0), - indexLength(5), - indexDecimals(3), - tsModulo(1), mesh(mesh_) { FUNCNAME("FileWriter::FileWriter()"); + initialize(); readParameters(); for (int i = 0; i < static_cast<int>(vecs.size()); i++) { @@ -73,6 +52,69 @@ namespace AMDiS { solutionVecs_ = vecs; } + + FileWriter::FileWriter(const ::std::string &name_, + Mesh *mesh_, + DOFVector< WorldVector<double> > *vec) + : name(name_), + mesh(mesh_) + { + FUNCNAME("FileWriter::FileWriter()"); + + initialize(); + readParameters(); + + // Create the temporal DOFVectors for all components of WorldVector. + nTmpSolutions_ = (*vec)[0].getSize(); + solutionVecs_.resize(nTmpSolutions_); + for (int i = 0; i < nTmpSolutions_; i++) { + solutionVecs_[i] = NEW DOFVector<double>(vec->getFESpace(), ""); + } + + // Copy the components of the WorldVectors to different DOFVectors + // of double values. + DOFVector< WorldVector<double> >::Iterator it(vec, USED_DOFS); + int counter = 0; + for (it.reset(); !it.end(); ++it, counter++) { + for (int i = 0; i < nTmpSolutions_; i++) { + (*solutionVecs_[i])[counter] = (*it)[i]; + } + } + + feSpace = vec->getFESpace(); + } + + + FileWriter::~FileWriter() + { + // Do not forget to delete temporal solution vector, if there have been + // some created in the constructor. + if (nTmpSolutions_ > 0) { + for (int i = 0; i < nTmpSolutions_; i++) { + DELETE solutionVecs_[i]; + } + } + } + + + void FileWriter::initialize() + { + tecplotExt = ".tec"; + amdisMeshExt = ".mesh"; + amdisDataExt = ".dat"; + paraViewFileExt = ".vtu"; + periodicFileExt = ".per"; + writeTecPlotFormat = 0; + writeAMDiSFormat = 0; + writeParaViewFormat = 0; + writePeriodicFormat = 0; + appendIndex = 0; + indexLength = 5; + indexDecimals = 3; + tsModulo = 1; + nTmpSolutions_ = 0; + } + void FileWriter::readParameters() { FUNCNAME("FileWriter::readParamters()"); @@ -136,7 +178,6 @@ namespace AMDiS { } } - if (writeTecPlotFormat) { TecPlotWriter<DOFVector<double> >::writeValues(solutionVecs_[0], const_cast<char*>((fn + tecplotExt).c_str()), diff --git a/AMDiS/src/FileWriter.h b/AMDiS/src/FileWriter.h index f76ce925141891eded71ccfad01bfe911adae803..26b7ee06af3deda31e6a0aca4e1797fa0bb39322 100644 --- a/AMDiS/src/FileWriter.h +++ b/AMDiS/src/FileWriter.h @@ -128,10 +128,18 @@ namespace AMDiS { Mesh *mesh_, ::std::vector< DOFVector<double>* > vecs); + /** \brief + * Constructor for a filewriter, when the solution vector is a vector + * of WorldVectors. + */ + FileWriter(const ::std::string &name_, + Mesh *mesh_, + DOFVector< WorldVector<double> > *vec); + /** \brief * Destructor. */ - virtual ~FileWriter() {}; + virtual ~FileWriter(); /** \brief * Implementation of FileWriterInterface::writeFiles(). @@ -142,6 +150,11 @@ namespace AMDiS { bool (*writeElem)(ElInfo*) = NULL); protected: + /** \brief + * Initialization of the filewriter. + */ + void initialize(); + /** \brief * Reads all file writer dependend parameters from the init file. */ @@ -237,11 +250,16 @@ namespace AMDiS { const FiniteElemSpace *feSpace; /** \brief - * Pointer to a vector which stores the solution. + * Pointers to the vectors which store the solution. */ - DOFVector<double> *vec_; - ::std::vector< DOFVector<double>* > solutionVecs_; + + /** \brief + * Stores the number of temporal solutions vectors, which have been created + * in the constructor. If this number is greater than zero, the vectors + * stored in solutionVecs_ must be deleted in the destructor. + */ + int nTmpSolutions_; }; } diff --git a/AMDiS/src/MatrixVector.h b/AMDiS/src/MatrixVector.h index f6ff2a5d9b2a962d5e503789fc4e31f689e5d05d..f7e5fe2e1f35a37de231ada482ddb0207b9ba796 100644 --- a/AMDiS/src/MatrixVector.h +++ b/AMDiS/src/MatrixVector.h @@ -462,8 +462,8 @@ namespace AMDiS { template<typename T> inline const Vector<T>& add(const Vector<T>& v1, const Vector<T>& v2, Vector<T>& result) { - TEST_EXIT(v1.getSize() == v2.getSize())("invalid size\n"); - TEST_EXIT(v2.getSize() == result.getSize())("invalid size\n"); + TEST_EXIT(v1.getSize() == v2.getSize())("invalid size in test v1 == v2\n"); + TEST_EXIT(v2.getSize() == result.getSize())("invalid size in test v2 == result\n"); T *v1It, *v2It, *resultIt; for (v1It = v1.begin(), v2It = v2.begin(), resultIt = result.begin(); v1It != v1.end(); diff --git a/AMDiS/src/SystemVector.h b/AMDiS/src/SystemVector.h index d06cef478410c78387f0ef92c90b76775ab0cb79..3048f31b779987804d27c09bfc7eadc60064cc3d 100644 --- a/AMDiS/src/SystemVector.h +++ b/AMDiS/src/SystemVector.h @@ -134,9 +134,8 @@ namespace AMDiS { vectors(rhs.vectors.getSize()) { - int i; - for (i=0;i<vectors.getSize();i++) { - vectors[i]=new DOFVector<double>(*rhs.vectors[i]); + for (int i = 0; i < vectors.getSize();i++) { + vectors[i] = new DOFVector<double>(*rhs.vectors[i]); } };