Commit 45b07a0a authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

* Faster VTK file writing

* Faster serialization of all objects
parent 167413c4
...@@ -11,13 +11,13 @@ namespace AMDiS { ...@@ -11,13 +11,13 @@ namespace AMDiS {
char number[5]; char number[5];
for (int i = oldSize; i < newSize; i++) { for (int i = oldSize; i < newSize; i++) {
sprintf(number, "[%d]", i); sprintf(number, "[%d]", i);
scalContents[i] = new ScalContent(name + ::std::string(number)); scalContents[i] = new ScalContent(name + std::string(number));
} }
} }
} }
void AdaptInfo::serialize(::std::ostream& out) { void AdaptInfo::serialize(std::ostream& out) {
out << name << ::std::endl; out << name << "\n";
out.write(reinterpret_cast<const char*>(&maxSpaceIteration), sizeof(int)); out.write(reinterpret_cast<const char*>(&maxSpaceIteration), sizeof(int));
out.write(reinterpret_cast<const char*>(&spaceIteration), sizeof(int)); out.write(reinterpret_cast<const char*>(&spaceIteration), sizeof(int));
out.write(reinterpret_cast<const char*>(&timestepIteration), sizeof(int)); out.write(reinterpret_cast<const char*>(&timestepIteration), sizeof(int));
...@@ -63,9 +63,9 @@ namespace AMDiS { ...@@ -63,9 +63,9 @@ namespace AMDiS {
} }
} }
void AdaptInfo::deserialize(::std::istream& in) { void AdaptInfo::deserialize(std::istream& in) {
in >> name; in >> name;
in.get(); // because of ::std::endl in serialization in.get(); // because of std::endl in serialization
in.read(reinterpret_cast<char*>(&maxSpaceIteration), sizeof(int)); in.read(reinterpret_cast<char*>(&maxSpaceIteration), sizeof(int));
in.read(reinterpret_cast<char*>(&spaceIteration), sizeof(int)); in.read(reinterpret_cast<char*>(&spaceIteration), sizeof(int));
...@@ -91,7 +91,7 @@ namespace AMDiS { ...@@ -91,7 +91,7 @@ namespace AMDiS {
// if (!scalContents[i]) { // if (!scalContents[i]) {
char number[5]; char number[5];
sprintf(number, "[%d]", i); sprintf(number, "[%d]", i);
scalContents[i] = new ScalContent(name + ::std::string(number)); scalContents[i] = new ScalContent(name + std::string(number));
// } // }
in.read(reinterpret_cast<char*>(&(scalContents[i]->est_sum)), in.read(reinterpret_cast<char*>(&(scalContents[i]->est_sum)),
sizeof(double)); sizeof(double));
......
...@@ -52,7 +52,7 @@ namespace AMDiS { ...@@ -52,7 +52,7 @@ namespace AMDiS {
/** \brief /** \brief
* Constructor. * Constructor.
*/ */
ScalContent(::std::string prefix) ScalContent(std::string prefix)
: est_sum(0.0), : est_sum(0.0),
est_t_sum(0.0), est_t_sum(0.0),
est_max(0.0), est_max(0.0),
...@@ -150,7 +150,7 @@ namespace AMDiS { ...@@ -150,7 +150,7 @@ namespace AMDiS {
/** \brief /** \brief
* Constructor. * Constructor.
*/ */
AdaptInfo(::std::string name_, int size = 1) AdaptInfo(std::string name_, int size = 1)
: name(name_), : name(name_),
spaceIteration(-1), spaceIteration(-1),
maxSpaceIteration(-1), maxSpaceIteration(-1),
...@@ -189,7 +189,7 @@ namespace AMDiS { ...@@ -189,7 +189,7 @@ namespace AMDiS {
char number[5]; char number[5];
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
sprintf(number, "[%d]", i); sprintf(number, "[%d]", i);
scalContents[i] = new ScalContent(name + ::std::string(number)); scalContents[i] = new ScalContent(name + std::string(number));
} }
} }
}; };
...@@ -713,15 +713,15 @@ namespace AMDiS { ...@@ -713,15 +713,15 @@ namespace AMDiS {
} }
// ===== Serialiazable implementation ===== // ===== Serialiazable implementation =====
void serialize(::std::ostream& out); void serialize(std::ostream& out);
void deserialize(::std::istream& in); void deserialize(std::istream& in);
protected: protected:
/** \brief /** \brief
* Name. * Name.
*/ */
::std::string name; std::string name;
/** \brief /** \brief
* Current space iteration * Current space iteration
......
...@@ -30,7 +30,7 @@ namespace AMDiS { ...@@ -30,7 +30,7 @@ namespace AMDiS {
} }
// Check if the problem should be deserialized because of the -rs parameter. // Check if the problem should be deserialized because of the -rs parameter.
::std::string serializationFilename = ""; std::string serializationFilename = "";
GET_PARAMETER(0, "argv->rs", &serializationFilename); GET_PARAMETER(0, "argv->rs", &serializationFilename);
if (serializationFilename.compare("")) { if (serializationFilename.compare("")) {
...@@ -38,7 +38,7 @@ namespace AMDiS { ...@@ -38,7 +38,7 @@ namespace AMDiS {
// serialization file mentioned in the used init file. // serialization file mentioned in the used init file.
MSG("Deserialization from file: %s\n", queueSerializationFilename_.c_str()); MSG("Deserialization from file: %s\n", queueSerializationFilename_.c_str());
::std::ifstream in(queueSerializationFilename_.c_str()); std::ifstream in(queueSerializationFilename_.c_str());
deserialize(in); deserialize(in);
in.close(); in.close();
...@@ -54,14 +54,14 @@ namespace AMDiS { ...@@ -54,14 +54,14 @@ namespace AMDiS {
&readSerializationWithAdaptInfo); &readSerializationWithAdaptInfo);
if (readSerialization && readSerializationWithAdaptInfo) { if (readSerialization && readSerializationWithAdaptInfo) {
::std::string serializationFilename = ""; std::string serializationFilename = "";
GET_PARAMETER(0, (*problemStat).getName() + "->input->serialization filename", GET_PARAMETER(0, (*problemStat).getName() + "->input->serialization filename",
&serializationFilename); &serializationFilename);
TEST_EXIT(serializationFilename != "")("no serialization file\n"); TEST_EXIT(serializationFilename != "")("no serialization file\n");
MSG("Deserialization with AdaptInfo from file: %s\n", serializationFilename.c_str()); MSG("Deserialization with AdaptInfo from file: %s\n", serializationFilename.c_str());
::std::ifstream in(serializationFilename.c_str()); std::ifstream in(serializationFilename.c_str());
deserialize(in); deserialize(in);
in.close(); in.close();
} }
...@@ -243,7 +243,7 @@ namespace AMDiS { ...@@ -243,7 +243,7 @@ namespace AMDiS {
return errorCode; return errorCode;
} }
void AdaptInstationary::initialize(const ::std::string& aName) void AdaptInstationary::initialize(const std::string& aName)
{ {
FUNCNAME("AdaptInstationary::initialize()"); FUNCNAME("AdaptInstationary::initialize()");
...@@ -264,7 +264,7 @@ namespace AMDiS { ...@@ -264,7 +264,7 @@ namespace AMDiS {
return; return;
} }
void AdaptInstationary::serialize(::std::ostream &out) void AdaptInstationary::serialize(std::ostream &out)
{ {
FUNCNAME("AdaptInstationary::serialize()"); FUNCNAME("AdaptInstationary::serialize()");
...@@ -275,7 +275,7 @@ namespace AMDiS { ...@@ -275,7 +275,7 @@ namespace AMDiS {
} }
} }
void AdaptInstationary::deserialize(::std::istream &in) void AdaptInstationary::deserialize(std::istream &in)
{ {
FUNCNAME("AdaptInstationary::deserialize()"); FUNCNAME("AdaptInstationary::deserialize()");
...@@ -305,7 +305,7 @@ namespace AMDiS { ...@@ -305,7 +305,7 @@ namespace AMDiS {
} }
// Calculate the avarage of the last iterations. // Calculate the avarage of the last iterations.
::std::queue<int> tmpQueue = lastIterationsDuration_; std::queue<int> tmpQueue = lastIterationsDuration_;
int avrgLastIterations = 0; int avrgLastIterations = 0;
while (!tmpQueue.empty()) { while (!tmpQueue.empty()) {
avrgLastIterations += tmpQueue.front(); avrgLastIterations += tmpQueue.front();
...@@ -315,7 +315,7 @@ namespace AMDiS { ...@@ -315,7 +315,7 @@ namespace AMDiS {
// Check if there is enough time for a further iteration. // Check if there is enough time for a further iteration.
if (initialTimestamp_ + queueRuntime_ - currentTimestamp < avrgLastIterations * 2) { if (initialTimestamp_ + queueRuntime_ - currentTimestamp < avrgLastIterations * 2) {
::std::ofstream out(queueSerializationFilename_.c_str()); std::ofstream out(queueSerializationFilename_.c_str());
serialize(out); serialize(out);
out.close(); out.close();
......
...@@ -26,7 +26,9 @@ namespace AMDiS { ...@@ -26,7 +26,9 @@ namespace AMDiS {
: mesh(m), : mesh(m),
nrDOF(mesh->getDim(), NO_INIT), nrDOF(mesh->getDim(), NO_INIT),
nr0DOF(mesh->getDim(), NO_INIT) nr0DOF(mesh->getDim(), NO_INIT)
{ init(); } {
init();
}
DOFAdmin::DOFAdmin(Mesh* m,std::string aName) DOFAdmin::DOFAdmin(Mesh* m,std::string aName)
: name(aName), : name(aName),
...@@ -317,7 +319,7 @@ namespace AMDiS { ...@@ -317,7 +319,7 @@ namespace AMDiS {
void DOFAdmin::serialize(std::ostream &out) void DOFAdmin::serialize(std::ostream &out)
{ {
// write name // write name
out << name << std::endl; out << name << "\n";
// write dofFree // write dofFree
int s = static_cast<int>(dofFree.size()); int s = static_cast<int>(dofFree.size());
......
...@@ -25,10 +25,10 @@ namespace AMDiS { ...@@ -25,10 +25,10 @@ namespace AMDiS {
localAdmin_ = const_cast<DOFAdmin*>(feSpace->getAdmin()); localAdmin_ = const_cast<DOFAdmin*>(feSpace->getAdmin());
// === create vertex info vector === // === create vertex info vector ===
vertexInfos_ = NEW DOFVector< ::std::list<VertexInfo> >(feSpace, "vertex infos"); vertexInfos_ = NEW DOFVector< std::list<VertexInfo> >(feSpace, "vertex infos");
interpPointInd_ = NEW DOFVector<int>(feSpace, "interpolation point indices"); interpPointInd_ = NEW DOFVector<int>(feSpace, "interpolation point indices");
interpPointCoords_ = NEW DOFVector< ::std::list<WorldVector<double> > >(feSpace, "interpolation point coordinates"); interpPointCoords_ = NEW DOFVector< std::list<WorldVector<double> > >(feSpace, "interpolation point coordinates");
dofCoords_ = NEW DOFVector< ::std::list<WorldVector<double> > >(feSpace, "dof coords"); dofCoords_ = NEW DOFVector< std::list<WorldVector<double> > >(feSpace, "dof coords");
dim_ = mesh_->getDim(); dim_ = mesh_->getDim();
...@@ -46,7 +46,9 @@ namespace AMDiS { ...@@ -46,7 +46,9 @@ namespace AMDiS {
elementDataCollected_ = false; elementDataCollected_ = false;
valueDataCollected_ = false; valueDataCollected_ = false;
periodicDataCollected_ = false; periodicDataCollected_ = false;
}
vertexCoords = NEW WorldVector<double>;
}
DataCollector::~DataCollector() DataCollector::~DataCollector()
{ {
...@@ -54,6 +56,7 @@ namespace AMDiS { ...@@ -54,6 +56,7 @@ namespace AMDiS {
DELETE interpPointInd_; DELETE interpPointInd_;
DELETE interpPointCoords_; DELETE interpPointCoords_;
DELETE dofCoords_; DELETE dofCoords_;
DELETE vertexCoords;
} }
void DataCollector::fillAllData() void DataCollector::fillAllData()
...@@ -120,7 +123,7 @@ namespace AMDiS { ...@@ -120,7 +123,7 @@ namespace AMDiS {
basisFcts_ = const_cast<BasisFunction*>(feSpace_->getBasisFcts()); basisFcts_ = const_cast<BasisFunction*>(feSpace_->getBasisFcts());
nBasisFcts_ = basisFcts_->getNumber(); nBasisFcts_ = basisFcts_->getNumber();
localDOFs_ = GET_MEMORY(DegreeOfFreedom, basisFcts_->getNumber()); localDOFs_ = GET_MEMORY(DegreeOfFreedom, nBasisFcts_);
TraverseStack stack; TraverseStack stack;
...@@ -134,25 +137,29 @@ namespace AMDiS { ...@@ -134,25 +137,29 @@ namespace AMDiS {
addValueData(elInfo); addValueData(elInfo);
elInfo = stack.traverseNext(elInfo); elInfo = stack.traverseNext(elInfo);
} }
// Remove all interpolation marks and, instead, set to each
// interpolation point its continous index starting from 0.
int i = 0;
for (intPointIt.reset(); !intPointIt.end(); ++intPointIt) {
if (*intPointIt == -3) {
*intPointIt = i++;
}
}
// Traverse elements to create interpolation values. // If there are interpolation points, add them to the corresponding
elInfo = stack.traverseFirst(mesh_, level_, traverseFlag_ | Mesh::FILL_COORDS); // data array.
while (elInfo) { if (nInterpPoints_ > 0) {
if (!writeElem_ || writeElem_(elInfo)) // Remove all interpolation marks and, instead, set to each
addInterpData(elInfo); // interpolation point its continous index starting from 0.
elInfo = stack.traverseNext(elInfo); int i = 0;
for (intPointIt.reset(); !intPointIt.end(); ++intPointIt) {
if (*intPointIt == -3) {
*intPointIt = i++;
}
}
// Traverse elements to create interpolation values.
elInfo = stack.traverseFirst(mesh_, level_, traverseFlag_ | Mesh::FILL_COORDS);
while (elInfo) {
if (!writeElem_ || writeElem_(elInfo))
addInterpData(elInfo);
elInfo = stack.traverseNext(elInfo);
}
} }
FREE_MEMORY(localDOFs_, DegreeOfFreedom, feSpace_->getBasisFcts()->getNumber()); FREE_MEMORY(localDOFs_, DegreeOfFreedom, nBasisFcts_);
valueDataCollected_ = true; valueDataCollected_ = true;
return(0); return(0);
...@@ -245,7 +252,7 @@ namespace AMDiS { ...@@ -245,7 +252,7 @@ namespace AMDiS {
vertexDOF = dof[i][nPreDofs_]; vertexDOF = dof[i][nPreDofs_];
// search for coords at this dof // search for coords at this dof
::std::list<VertexInfo>::iterator it = std::list<VertexInfo>::iterator it =
find((*vertexInfos_)[vertexDOF].begin(), find((*vertexInfos_)[vertexDOF].begin(),
(*vertexInfos_)[vertexDOF].end(), (*vertexInfos_)[vertexDOF].end(),
vertexCoords); vertexCoords);
...@@ -289,7 +296,7 @@ namespace AMDiS { ...@@ -289,7 +296,7 @@ namespace AMDiS {
FUNCNAME("DataCollector::addValueData()"); FUNCNAME("DataCollector::addValueData()");
basisFcts_->getLocalIndices(elInfo->getElement(), localAdmin_, localDOFs_); basisFcts_->getLocalIndices(elInfo->getElement(), localAdmin_, localDOFs_);
WorldVector<double> vertexCoords; // WorldVector<double> vertexCoords;
// First, traverse all DOFs at the vertices of the element, determine // First, traverse all DOFs at the vertices of the element, determine
// their coordinates and add them to the corresponding entry in dofCoords_. // their coordinates and add them to the corresponding entry in dofCoords_.
...@@ -299,18 +306,18 @@ namespace AMDiS { ...@@ -299,18 +306,18 @@ namespace AMDiS {
(*interpPointInd_)[dofi] = -2; // mark as vertex (*interpPointInd_)[dofi] = -2; // mark as vertex
// get coords of this vertex // get coords of this vertex
vertexCoords = elInfo->getCoord(i); *vertexCoords = elInfo->getCoord(i);
// search for coords at this dof // search for coords at this dof
::std::list<WorldVector<double> >::iterator it = std::list<WorldVector<double> >::iterator it =
find((*dofCoords_)[dofi].begin(), find((*dofCoords_)[dofi].begin(),
(*dofCoords_)[dofi].end(), (*dofCoords_)[dofi].end(),
vertexCoords); *vertexCoords);
// coords not yet in list? // coords not yet in list?
if (it == (*dofCoords_)[dofi].end()) { if (it == (*dofCoords_)[dofi].end()) {
// add new coords to list // add new coords to list
(*dofCoords_)[dofi].push_back(vertexCoords); (*dofCoords_)[dofi].push_back(*vertexCoords);
} }
} }
...@@ -322,7 +329,7 @@ namespace AMDiS { ...@@ -322,7 +329,7 @@ namespace AMDiS {
for (int i = mesh_->getGeo(VERTEX); i < nBasisFcts_; i++) { for (int i = mesh_->getGeo(VERTEX); i < nBasisFcts_; i++) {
DegreeOfFreedom dofi = localDOFs_[i]; DegreeOfFreedom dofi = localDOFs_[i];
elInfo->coordToWorld(*basisFcts_->getCoords(i), &vertexCoords); elInfo->coordToWorld(*basisFcts_->getCoords(i), vertexCoords);
if ((*interpPointInd_)[dofi] == -1) { if ((*interpPointInd_)[dofi] == -1) {
// mark as interpolation point // mark as interpolation point
...@@ -330,13 +337,13 @@ namespace AMDiS { ...@@ -330,13 +337,13 @@ namespace AMDiS {
// search for interpolation point coordinates, and insert them to the // search for interpolation point coordinates, and insert them to the
// dof-entry, if not contained in the list // dof-entry, if not contained in the list
::std::list<WorldVector<double> >::iterator it = std::list<WorldVector<double> >::iterator it =
find((*interpPointCoords_)[dofi].begin(), find((*interpPointCoords_)[dofi].begin(),
(*interpPointCoords_)[dofi].end(), (*interpPointCoords_)[dofi].end(),
vertexCoords); *vertexCoords);
if (it == (*interpPointCoords_)[dofi].end()) { if (it == (*interpPointCoords_)[dofi].end()) {
(*interpPointCoords_)[dofi].push_back(vertexCoords); (*interpPointCoords_)[dofi].push_back(*vertexCoords);
nInterpPoints_++; nInterpPoints_++;
} }
} }
...@@ -355,7 +362,7 @@ namespace AMDiS { ...@@ -355,7 +362,7 @@ namespace AMDiS {
for (int i = mesh_->getGeo(VERTEX); i < nBasisFcts_; i++) { for (int i = mesh_->getGeo(VERTEX); i < nBasisFcts_; i++) {
elemInterpPoints.push_back((*interpPointInd_)[localDOFs_[i]]); elemInterpPoints.push_back((*interpPointInd_)[localDOFs_[i]]);
} }
interpPoints_.push_back(elemInterpPoints); interpPoints_.push_back(elemInterpPoints);
return(0); return(0);
...@@ -370,7 +377,7 @@ namespace AMDiS { ...@@ -370,7 +377,7 @@ namespace AMDiS {
getElementData(PERIODIC)); getElementData(PERIODIC));
if (ldp) { if (ldp) {
::std::list<LeafDataPeriodic::PeriodicInfo>::iterator it; std::list<LeafDataPeriodic::PeriodicInfo>::iterator it;
for (it = dynamic_cast<LeafDataPeriodic*>(ldp)->getInfoList().begin(); for (it = dynamic_cast<LeafDataPeriodic*>(ldp)->getInfoList().begin();
it != dynamic_cast<LeafDataPeriodic*>(ldp)->getInfoList().end(); it != dynamic_cast<LeafDataPeriodic*>(ldp)->getInfoList().end();
...@@ -422,7 +429,7 @@ namespace AMDiS { ...@@ -422,7 +429,7 @@ namespace AMDiS {
return(0); return(0);
} }
::std::list<ElementInfo>* DataCollector::getElementInfos() std::list<ElementInfo>* DataCollector::getElementInfos()
{ {
if (!elementDataCollected_) { if (!elementDataCollected_) {
startCollectingElementData(); startCollectingElementData();
...@@ -431,7 +438,7 @@ namespace AMDiS { ...@@ -431,7 +438,7 @@ namespace AMDiS {
return &elements_; return &elements_;
} }
DOFVector< ::std::list<VertexInfo> >* DataCollector::getVertexInfos() DOFVector< std::list<VertexInfo> >* DataCollector::getVertexInfos()
{ {
if (!elementDataCollected_) { if (!elementDataCollected_) {
startCollectingElementData(); startCollectingElementData();
...@@ -440,7 +447,7 @@ namespace AMDiS { ...@@ -440,7 +447,7 @@ namespace AMDiS {
return vertexInfos_; return vertexInfos_;
} }
::std::list<PeriodicInfo>* DataCollector::getPeriodicInfos() std::list<PeriodicInfo>* DataCollector::getPeriodicInfos()
{ {
if (!periodicDataCollected_) { if (!periodicDataCollected_) {
startCollectingPeriodicData(); startCollectingPeriodicData();
...@@ -504,7 +511,7 @@ namespace AMDiS { ...@@ -504,7 +511,7 @@ namespace AMDiS {
return values_; return values_;
} }
DOFVector< ::std::list<WorldVector<double> > >* DataCollector::getDofCoords() DOFVector< std::list<WorldVector<double> > >* DataCollector::getDofCoords()
{ {
if (!valueDataCollected_) { if (!valueDataCollected_) {
startCollectingValueData(); startCollectingValueData();
...@@ -522,7 +529,7 @@ namespace AMDiS { ...@@ -522,7 +529,7 @@ namespace AMDiS {
return interpPointInd_; return interpPointInd_;
} }
DOFVector< ::std::list<WorldVector<double> > >* DataCollector::getInterpPointCoords() DOFVector< std::list<WorldVector<double> > >* DataCollector::getInterpPointCoords()
{ {
if (!valueDataCollected_) { if (!valueDataCollected_) {
startCollectingValueData(); startCollectingValueData();
...@@ -531,7 +538,7 @@ namespace AMDiS { ...@@ -531,7 +538,7 @@ namespace AMDiS {
return interpPointCoords_; return interpPointCoords_;
} }
::std::vector< ::std::vector<int> >* DataCollector::getInterpPoints() std::vector< std::vector<int> >* DataCollector::getInterpPoints()
{ {
if (!valueDataCollected_) { if (!valueDataCollected_) {
startCollectingValueData(); startCollectingValueData();
......
...@@ -69,12 +69,12 @@ namespace AMDiS { ...@@ -69,12 +69,12 @@ namespace AMDiS {
/** \brief /** \brief
* Returns list with element information. * Returns list with element information.
*/ */
::std::list<ElementInfo>* getElementInfos(); std::list<ElementInfo>* getElementInfos();
/** \brief /** \brief
* Returns vector with vertex information. * Returns vector with vertex information.
*/ */
DOFVector< ::std::list<VertexInfo> >* getVertexInfos(); DOFVector< std::list<VertexInfo> >* getVertexInfos();
/** \brief /** \brief
* Returns the finite element space of the problem. * Returns the finite element space of the problem.
...@@ -89,7 +89,7 @@ namespace AMDiS { ...@@ -89,7 +89,7 @@ namespace AMDiS {
/** \brief /** \brief
* Returns vector with information about dof coordinates. * Returns vector with information about dof coordinates.
*/ */