From 7f20a14687dc7a018c35d4d246e9fd95cfd75f31 Mon Sep 17 00:00:00 2001 From: Simon Praetorius <simon.praetorius@tu-dresden.de> Date: Wed, 12 May 2010 08:21:10 +0000 Subject: [PATCH] Elementfunction.h: Aenderung nach AMDiS Umstellung Pointer->Referenz noetig, VTK-Writer: Moeglichkeit zu Schreiben von Vektoren von DOFVectoren geschaffen --- AMDiS/src/ElementFunction.h | 20 ++++----- AMDiS/src/VtkWriter.cc | 87 +++++++++++++++++++++++++------------ AMDiS/src/VtkWriter.h | 13 ++++++ 3 files changed, 83 insertions(+), 37 deletions(-) diff --git a/AMDiS/src/ElementFunction.h b/AMDiS/src/ElementFunction.h index 53fdf2e0..8576d80a 100644 --- a/AMDiS/src/ElementFunction.h +++ b/AMDiS/src/ElementFunction.h @@ -35,21 +35,21 @@ namespace AMDiS { public: /// constructor. ElementFunction() - : elInfo_(NULL) + : elInfo(NULL) {} /// destructor. virtual ~ElementFunction() {} /// sets \ref elInfo_; - inline void setElInfo(const ElInfo *elInfo) + inline void setElInfo(const ElInfo *elInfo_) { - elInfo_ = elInfo; + elInfo = elInfo_; } protected: /// ElInfo the function currently lives on. - const ElInfo *elInfo_; + const ElInfo *elInfo; }; /// ElementFunction wich encapsulates the evaluation of an analytical function. @@ -58,22 +58,22 @@ namespace AMDiS { { public: /// constructor - ElementFunctionAnalytic(const AbstractFunction<T, WorldVector<double> > *fct) + ElementFunctionAnalytic(const AbstractFunction<T, WorldVector<double> > *fct_) : ElementFunction<T>(), - fct_(fct) + fct(fct_) {} /// evaluation at given coordinates. T operator()(const DimVec<double>& bary) const { WorldVector<double> worldCoords; - this->elInfo_->coordToWorld(bary, &worldCoords); - return (*fct_)(worldCoords); + this->elInfo->coordToWorld(bary, worldCoords); + return (*fct)(worldCoords); } protected: /// function to be avaluated at world coordinates. - const AbstractFunction<T, WorldVector<double> > *fct_; + const AbstractFunction<T, WorldVector<double> > *fct; }; @@ -92,7 +92,7 @@ namespace AMDiS { T operator()(const DimVec<double>& bary) const { T* localVec = new T[dofVector->getFESpace()->getBasisFcts()->getNumber()]; - dofVector->getLocalVector(this->elInfo_->getElement(), localVec); + dofVector->getLocalVector(this->elInfo->getElement(), localVec); T t = dofVector->getFESpace()->getBasisFcts()->evalUh(bary, localVec); delete [] localVec; diff --git a/AMDiS/src/VtkWriter.cc b/AMDiS/src/VtkWriter.cc index a987d954..885c53e3 100644 --- a/AMDiS/src/VtkWriter.cc +++ b/AMDiS/src/VtkWriter.cc @@ -129,32 +129,65 @@ namespace AMDiS { } void VtkWriter::writeFile(DOFVector<double> *values, - std::string filename, - bool writeParallel) + std::string filename, + bool writeParallel) { - FUNCNAME("VtkWriter::writeFile()"); - - DataCollector dc(values->getFESpace(), values); - std::vector<DataCollector*> dcList(0); - dcList.push_back(&dc); - VtkWriter writer(&dcList); - -#ifdef HAVE_PARALLEL_DOMAIN_AMDIS - if (writeParallel) { - using boost::lexical_cast; - - int sPos = filename.find(".vtu"); - TEST_EXIT(sPos >= 0)("Failed to find file postfix!\n"); - std::string name = filename.substr(0, sPos); - - if (MPI::COMM_WORLD.Get_rank() == 0) - writer.writeParallelFile(name + ".pvtu", MPI::COMM_WORLD.Get_size(), name, ".vtu"); - - filename = name + "-p" + lexical_cast<std::string>(MPI::COMM_WORLD.Get_rank()) + "-.vtu"; - } -#endif - - writer.writeFile(filename); - } - + FUNCNAME("VtkWriter::writeFile()"); + + DataCollector dc(values->getFESpace(), values); + std::vector<DataCollector*> dcList(0); + dcList.push_back(&dc); + VtkWriter::writeFile(dcList,filename,writeParallel); + }; + + void VtkWriter::writeFile(std::vector<DOFVector<double>* > &values, + std::string filename, + bool writeParallel) + { + std::vector<DataCollector*> dcList(0); + for(unsigned i=0; i<values.size(); ++i) { + dcList.push_back(new DataCollector(values[i]->getFESpace(), values[i])); + } + VtkWriter::writeFile(dcList,filename,writeParallel); + for(unsigned i=0; i<values.size(); ++i) { + delete dcList[i]; + } + }; + + void VtkWriter::writeFile(SystemVector *values, + std::string filename, + bool writeParallel) + { + std::vector<DataCollector*> dcList(0); + for(unsigned i=0; i<values->getSize(); ++i) { + dcList.push_back(new DataCollector(values->getDOFVector(i)->getFESpace(), values->getDOFVector(i))); + } + VtkWriter::writeFile(dcList,filename,writeParallel); + for(unsigned i=0; i<dcList.size(); ++i) { + delete dcList[i]; + } + }; + + void VtkWriter::writeFile(std::vector<DataCollector*> &dcList, + std::string filename, + bool writeParallel) + { + VtkWriter writer(&dcList); + + #ifdef HAVE_PARALLEL_DOMAIN_AMDIS + if (writeParallel) { + using boost::lexical_cast; + + int sPos = filename.find(".vtu"); + TEST_EXIT(sPos >= 0)("Failed to find file postfix!\n"); + std::string name = filename.substr(0, sPos); + + if (MPI::COMM_WORLD.Get_rank() == 0) + writer.writeParallelFile(name + ".pvtu", MPI::COMM_WORLD.Get_size(), name, ".vtu"); + + filename = name + "-p" + lexical_cast<std::string>(MPI::COMM_WORLD.Get_rank()) + "-.vtu"; + } + #endif + writer.writeFile(filename); + }; } diff --git a/AMDiS/src/VtkWriter.h b/AMDiS/src/VtkWriter.h index 9981748b..52ef3184 100644 --- a/AMDiS/src/VtkWriter.h +++ b/AMDiS/src/VtkWriter.h @@ -33,6 +33,7 @@ #include "BasisFunction.h" #include "DataCollector.h" #include "FileWriter.h" +#include "SystemVector.h" namespace AMDiS { @@ -67,6 +68,18 @@ namespace AMDiS { writeFile(&values, filename, writeParallel); } + /// May be used to simply write ParaView files with a list of values. + static void writeFile(std::vector<DOFVector<double>*> &values, + std::string filename, + bool writeParallel = true); + static void writeFile(SystemVector *values, + std::string filename, + bool writeParallel = true); + + static void writeFile(std::vector<DataCollector*> &dcList, + std::string filename, + bool writeParallel = true); + /// Set a compressing method for file output. void setCompression(FileCompression c) { -- GitLab