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

* Faster VTK file writing

* Faster serialization of all objects
parent 167413c4
......@@ -11,13 +11,13 @@ namespace AMDiS {
char number[5];
for (int i = oldSize; i < newSize; 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) {
out << name << ::std::endl;
void AdaptInfo::serialize(std::ostream& out) {
out << name << "\n";
out.write(reinterpret_cast<const char*>(&maxSpaceIteration), sizeof(int));
out.write(reinterpret_cast<const char*>(&spaceIteration), sizeof(int));
out.write(reinterpret_cast<const char*>(&timestepIteration), sizeof(int));
......@@ -63,9 +63,9 @@ namespace AMDiS {
}
}
void AdaptInfo::deserialize(::std::istream& in) {
void AdaptInfo::deserialize(std::istream& in) {
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*>(&spaceIteration), sizeof(int));
......@@ -91,7 +91,7 @@ namespace AMDiS {
// if (!scalContents[i]) {
char number[5];
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)),
sizeof(double));
......
......@@ -52,7 +52,7 @@ namespace AMDiS {
/** \brief
* Constructor.
*/
ScalContent(::std::string prefix)
ScalContent(std::string prefix)
: est_sum(0.0),
est_t_sum(0.0),
est_max(0.0),
......@@ -150,7 +150,7 @@ namespace AMDiS {
/** \brief
* Constructor.
*/
AdaptInfo(::std::string name_, int size = 1)
AdaptInfo(std::string name_, int size = 1)
: name(name_),
spaceIteration(-1),
maxSpaceIteration(-1),
......@@ -189,7 +189,7 @@ namespace AMDiS {
char number[5];
for (int i = 0; i < size; 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 {
}
// ===== Serialiazable implementation =====
void serialize(::std::ostream& out);
void serialize(std::ostream& out);
void deserialize(::std::istream& in);
void deserialize(std::istream& in);
protected:
/** \brief
* Name.
*/
::std::string name;
std::string name;
/** \brief
* Current space iteration
......
......@@ -30,7 +30,7 @@ namespace AMDiS {
}
// Check if the problem should be deserialized because of the -rs parameter.
::std::string serializationFilename = "";
std::string serializationFilename = "";
GET_PARAMETER(0, "argv->rs", &serializationFilename);
if (serializationFilename.compare("")) {
......@@ -38,7 +38,7 @@ namespace AMDiS {
// serialization file mentioned in the used init file.
MSG("Deserialization from file: %s\n", queueSerializationFilename_.c_str());
::std::ifstream in(queueSerializationFilename_.c_str());
std::ifstream in(queueSerializationFilename_.c_str());
deserialize(in);
in.close();
......@@ -54,14 +54,14 @@ namespace AMDiS {
&readSerializationWithAdaptInfo);
if (readSerialization && readSerializationWithAdaptInfo) {
::std::string serializationFilename = "";
std::string serializationFilename = "";
GET_PARAMETER(0, (*problemStat).getName() + "->input->serialization filename",
&serializationFilename);
TEST_EXIT(serializationFilename != "")("no serialization file\n");
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);
in.close();
}
......@@ -243,7 +243,7 @@ namespace AMDiS {
return errorCode;
}
void AdaptInstationary::initialize(const ::std::string& aName)
void AdaptInstationary::initialize(const std::string& aName)
{
FUNCNAME("AdaptInstationary::initialize()");
......@@ -264,7 +264,7 @@ namespace AMDiS {
return;
}
void AdaptInstationary::serialize(::std::ostream &out)
void AdaptInstationary::serialize(std::ostream &out)
{
FUNCNAME("AdaptInstationary::serialize()");
......@@ -275,7 +275,7 @@ namespace AMDiS {
}
}
void AdaptInstationary::deserialize(::std::istream &in)
void AdaptInstationary::deserialize(std::istream &in)
{
FUNCNAME("AdaptInstationary::deserialize()");
......@@ -305,7 +305,7 @@ namespace AMDiS {
}
// Calculate the avarage of the last iterations.
::std::queue<int> tmpQueue = lastIterationsDuration_;
std::queue<int> tmpQueue = lastIterationsDuration_;
int avrgLastIterations = 0;
while (!tmpQueue.empty()) {
avrgLastIterations += tmpQueue.front();
......@@ -315,7 +315,7 @@ namespace AMDiS {
// Check if there is enough time for a further iteration.
if (initialTimestamp_ + queueRuntime_ - currentTimestamp < avrgLastIterations * 2) {
::std::ofstream out(queueSerializationFilename_.c_str());
std::ofstream out(queueSerializationFilename_.c_str());
serialize(out);
out.close();
......
......@@ -26,7 +26,9 @@ namespace AMDiS {
: mesh(m),
nrDOF(mesh->getDim(), NO_INIT),
nr0DOF(mesh->getDim(), NO_INIT)
{ init(); }
{
init();
}
DOFAdmin::DOFAdmin(Mesh* m,std::string aName)
: name(aName),
......@@ -317,7 +319,7 @@ namespace AMDiS {
void DOFAdmin::serialize(std::ostream &out)
{
// write name
out << name << std::endl;
out << name << "\n";
// write dofFree
int s = static_cast<int>(dofFree.size());
......
......@@ -25,10 +25,10 @@ namespace AMDiS {
localAdmin_ = const_cast<DOFAdmin*>(feSpace->getAdmin());
// === 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");
interpPointCoords_ = NEW DOFVector< ::std::list<WorldVector<double> > >(feSpace, "interpolation point coordinates");
dofCoords_ = NEW DOFVector< ::std::list<WorldVector<double> > >(feSpace, "dof coords");
interpPointCoords_ = NEW DOFVector< std::list<WorldVector<double> > >(feSpace, "interpolation point coordinates");
dofCoords_ = NEW DOFVector< std::list<WorldVector<double> > >(feSpace, "dof coords");
dim_ = mesh_->getDim();
......@@ -46,7 +46,9 @@ namespace AMDiS {
elementDataCollected_ = false;
valueDataCollected_ = false;
periodicDataCollected_ = false;
}
vertexCoords = NEW WorldVector<double>;
}
DataCollector::~DataCollector()
{
......@@ -54,6 +56,7 @@ namespace AMDiS {
DELETE interpPointInd_;
DELETE interpPointCoords_;
DELETE dofCoords_;
DELETE vertexCoords;
}
void DataCollector::fillAllData()
......@@ -120,7 +123,7 @@ namespace AMDiS {
basisFcts_ = const_cast<BasisFunction*>(feSpace_->getBasisFcts());
nBasisFcts_ = basisFcts_->getNumber();
localDOFs_ = GET_MEMORY(DegreeOfFreedom, basisFcts_->getNumber());
localDOFs_ = GET_MEMORY(DegreeOfFreedom, nBasisFcts_);
TraverseStack stack;
......@@ -134,25 +137,29 @@ namespace AMDiS {
addValueData(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.
elInfo = stack.traverseFirst(mesh_, level_, traverseFlag_ | Mesh::FILL_COORDS);
while (elInfo) {
if (!writeElem_ || writeElem_(elInfo))
addInterpData(elInfo);
elInfo = stack.traverseNext(elInfo);
// If there are interpolation points, add them to the corresponding
// data array.
if (nInterpPoints_ > 0) {
// 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.
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;
return(0);
......@@ -245,7 +252,7 @@ namespace AMDiS {
vertexDOF = dof[i][nPreDofs_];
// search for coords at this dof
::std::list<VertexInfo>::iterator it =
std::list<VertexInfo>::iterator it =
find((*vertexInfos_)[vertexDOF].begin(),
(*vertexInfos_)[vertexDOF].end(),
vertexCoords);
......@@ -289,7 +296,7 @@ namespace AMDiS {
FUNCNAME("DataCollector::addValueData()");
basisFcts_->getLocalIndices(elInfo->getElement(), localAdmin_, localDOFs_);
WorldVector<double> vertexCoords;
// WorldVector<double> vertexCoords;
// First, traverse all DOFs at the vertices of the element, determine
// their coordinates and add them to the corresponding entry in dofCoords_.
......@@ -299,18 +306,18 @@ namespace AMDiS {
(*interpPointInd_)[dofi] = -2; // mark as vertex
// get coords of this vertex
vertexCoords = elInfo->getCoord(i);
*vertexCoords = elInfo->getCoord(i);
// search for coords at this dof
::std::list<WorldVector<double> >::iterator it =
std::list<WorldVector<double> >::iterator it =
find((*dofCoords_)[dofi].begin(),
(*dofCoords_)[dofi].end(),
vertexCoords);
*vertexCoords);
// coords not yet in list?
if (it == (*dofCoords_)[dofi].end()) {
// add new coords to list
(*dofCoords_)[dofi].push_back(vertexCoords);
(*dofCoords_)[dofi].push_back(*vertexCoords);
}
}
......@@ -322,7 +329,7 @@ namespace AMDiS {
for (int i = mesh_->getGeo(VERTEX); i < nBasisFcts_; i++) {
DegreeOfFreedom dofi = localDOFs_[i];
elInfo->coordToWorld(*basisFcts_->getCoords(i), &vertexCoords);
elInfo->coordToWorld(*basisFcts_->getCoords(i), vertexCoords);
if ((*interpPointInd_)[dofi] == -1) {
// mark as interpolation point
......@@ -330,13 +337,13 @@ namespace AMDiS {
// search for interpolation point coordinates, and insert them to the
// dof-entry, if not contained in the list
::std::list<WorldVector<double> >::iterator it =
std::list<WorldVector<double> >::iterator it =
find((*interpPointCoords_)[dofi].begin(),
(*interpPointCoords_)[dofi].end(),
vertexCoords);
*vertexCoords);
if (it == (*interpPointCoords_)[dofi].end()) {
(*interpPointCoords_)[dofi].push_back(vertexCoords);
(*interpPointCoords_)[dofi].push_back(*vertexCoords);
nInterpPoints_++;
}
}
......@@ -355,7 +362,7 @@ namespace AMDiS {
for (int i = mesh_->getGeo(VERTEX); i < nBasisFcts_; i++) {
elemInterpPoints.push_back((*interpPointInd_)[localDOFs_[i]]);
}
interpPoints_.push_back(elemInterpPoints);
return(0);
......@@ -370,7 +377,7 @@ namespace AMDiS {
getElementData(PERIODIC));
if (ldp) {
::std::list<LeafDataPeriodic::PeriodicInfo>::iterator it;
std::list<LeafDataPeriodic::PeriodicInfo>::iterator it;
for (it = dynamic_cast<LeafDataPeriodic*>(ldp)->getInfoList().begin();
it != dynamic_cast<LeafDataPeriodic*>(ldp)->getInfoList().end();
......@@ -422,7 +429,7 @@ namespace AMDiS {
return(0);
}
::std::list<ElementInfo>* DataCollector::getElementInfos()
std::list<ElementInfo>* DataCollector::getElementInfos()
{
if (!elementDataCollected_) {
startCollectingElementData();
......@@ -431,7 +438,7 @@ namespace AMDiS {
return &elements_;
}
DOFVector< ::std::list<VertexInfo> >* DataCollector::getVertexInfos()
DOFVector< std::list<VertexInfo> >* DataCollector::getVertexInfos()
{
if (!elementDataCollected_) {
startCollectingElementData();
......@@ -440,7 +447,7 @@ namespace AMDiS {
return vertexInfos_;
}
::std::list<PeriodicInfo>* DataCollector::getPeriodicInfos()
std::list<PeriodicInfo>* DataCollector::getPeriodicInfos()
{
if (!periodicDataCollected_) {
startCollectingPeriodicData();
......@@ -504,7 +511,7 @@ namespace AMDiS {
return values_;
}
DOFVector< ::std::list<WorldVector<double> > >* DataCollector::getDofCoords()
DOFVector< std::list<WorldVector<double> > >* DataCollector::getDofCoords()
{
if (!valueDataCollected_) {
startCollectingValueData();
......@@ -522,7 +529,7 @@ namespace AMDiS {
return interpPointInd_;
}
DOFVector< ::std::list<WorldVector<double> > >* DataCollector::getInterpPointCoords()
DOFVector< std::list<WorldVector<double> > >* DataCollector::getInterpPointCoords()
{
if (!valueDataCollected_) {
startCollectingValueData();
......@@ -531,7 +538,7 @@ namespace AMDiS {
return interpPointCoords_;
}
::std::vector< ::std::vector<int> >* DataCollector::getInterpPoints()
std::vector< std::vector<int> >* DataCollector::getInterpPoints()
{
if (!valueDataCollected_) {
startCollectingValueData();
......
......@@ -69,12 +69,12 @@ namespace AMDiS {
/** \brief
* Returns list with element information.
*/
::std::list<ElementInfo>* getElementInfos();
std::list<ElementInfo>* getElementInfos();
/** \brief
* Returns vector with vertex information.
*/
DOFVector< ::std::list<VertexInfo> >* getVertexInfos();
DOFVector< std::list<VertexInfo> >* getVertexInfos();
/** \brief
* Returns the finite element space of the problem.
......@@ -89,7 +89,7 @@ namespace AMDiS {
/** \brief
* Returns vector with information about dof coordinates.
*/
DOFVector< ::std::list<WorldVector<double> > >* getDofCoords();
DOFVector< std::list<WorldVector<double> > >* getDofCoords();
/** \brief
* Returns vector with information about interpolation
......@@ -100,17 +100,17 @@ namespace AMDiS {
/** \brief
*
*/
DOFVector< ::std::list<WorldVector<double> > >* getInterpPointCoords();
DOFVector< std::list<WorldVector<double> > >* getInterpPointCoords();
/** \brief
* Returns list of interpolation point information.
*/
::std::vector< ::std::vector<int> >* getInterpPoints();
std::vector< std::vector<int> >* getInterpPoints();
/** \brief
* Returns list of information about periodics.
*/
::std::list<PeriodicInfo>* getPeriodicInfos();
std::list<PeriodicInfo>* getPeriodicInfos();
/** \brief
* Returns the number of vertices.
......@@ -241,7 +241,7 @@ namespace AMDiS {
/** \brief
* Maps internal element indices to global output indices.
*/
::std::map<int, int> outputIndices_;
std::map<int, int> outputIndices_;
/** \brief
* Global interpolation point indexing
......@@ -251,39 +251,39 @@ namespace AMDiS {
/** \brief
* Stores for each simplex the interpolation points.
*/
::std::vector< ::std::vector<int> > interpPoints_;
std::vector< std::vector<int> > interpPoints_;
/** \brief
* Stores for each DOF a list of its coordinates. If there are now periodic
* boundaries than there is also only one coordinate per DOF.
*/
DOFVector< ::std::list<WorldVector<double> > > *interpPointCoords_;
DOFVector< std::list<WorldVector<double> > > *interpPointCoords_;
/** \brief
* list of coords for each dof
*/
DOFVector< ::std::list<WorldVector<double> > > *dofCoords_;
DOFVector< std::list<WorldVector<double> > > *dofCoords_;
/** \brief
* List that stores an ElementInfo for each element.
*/
::std::list<ElementInfo> elements_;
std::list<ElementInfo> elements_;
/** \brief
* List stat stores information about all periodics.
*/
::std::list<PeriodicInfo> periodicInfos_;
std::list<PeriodicInfo> periodicInfos_;
/** \brief
* Stores a list of vertex infos for each dof.
*/
DOFVector< ::std::list<VertexInfo> > *vertexInfos_;
DOFVector< std::list<VertexInfo> > *vertexInfos_;
/** \brief
* periodicConnections[i][j] stores whether the connection at side j of
* the element with output index i has already been written.
*/
::std::vector<DimVec<bool> > periodicConnections_;
std::vector<DimVec<bool> > periodicConnections_;
/** \brief
* Stores if element data was collected before.
......@@ -316,9 +316,14 @@ namespace AMDiS {
BasisFunction *basisFcts_;
/** \brief
* Temporaru variable used in functions addValueData() and addInterpData().
* Temporary variable used in functions addValueData() and addInterpData().
*/
int nBasisFcts_;
/** \brief
* Temporary variable used in function \ref addValueData.
*/
WorldVector<double> *vertexCoords;
};
}
......
......@@ -252,39 +252,37 @@ namespace AMDiS {
};
}
void Element::serialize(::std::ostream &out)
void Element::serialize(std::ostream &out)
{
// write children
if(child[0]) {
out << child[0]->getTypeName() << ::std::endl;
out << child[0]->getTypeName() << "\n";
child[0]->serialize(out);
child[1]->serialize(out);
} else {
out << "NULL" << ::std::endl;
out << "NULL\n";
}
// write dofs
int dim = mesh->getDim();
int nodes = mesh->getNumberOfNodes();
int j = 0;
out.write(reinterpret_cast<const char*>(&nodes), sizeof(int));
int i, j = 0, ndof, pos;
for(pos = 0; pos <= dim; pos++) {
for (int pos = 0; pos <= dim; pos++) {
GeoIndex position = INDEX_OF_DIM(pos ,dim);
int ndof = 0;
ndof = 0;
for (i = 0; i < mesh->getNumberOfDOFAdmin(); i++) {
for (int i = 0; i < mesh->getNumberOfDOFAdmin(); i++) {
const DOFAdmin *localAdmin = &mesh->getDOFAdmin(i);
TEST_EXIT_DBG(localAdmin)("no admin[%d]\n", i);
ndof += localAdmin->getNumberOfDOFs(position);
}
if(ndof > 0) {
for(i = 0; i < mesh->getGeo(position); i++) {
if(dof[j] != NULL) {
if(Mesh::serializedDOFs[dof[j][0]] == NULL) {
if (ndof > 0) {
for (int i = 0; i < mesh->getGeo(position); i++) {
if (dof[j] != NULL) {
if (Mesh::serializedDOFs[dof[j][0]] == NULL) {
Mesh::serializedDOFs[dof[j][0]] = dof[j];
out.write(reinterpret_cast<const char*>(&ndof), sizeof(int));
out.write(reinterpret_cast<const char*>(dof[j]),
......@@ -310,40 +308,40 @@ namespace AMDiS {
out.write(reinterpret_cast<const char*>(&mark), sizeof(signed char));
// write newCoord
if(newCoord) {
out << "WorldVector" << ::std::endl;
if (newCoord) {
out << "WorldVector\n";
newCoord->serialize(out);
} else {
out << "NULL" << ::std::endl;
out << "NULL\n";
}
// write element data
if(elementData) {
out << elementData->getTypeName() << ::std::endl;
if (elementData) {
out << elementData->getTypeName() << "\n";
elementData->serialize(out);
} else {
out << "NULL" << ::std::endl;
out << "NULL\n";
}
}
void Element::deserialize(::std::istream &in)
void Element::deserialize(std::istream &in)
{
::std::string typeName;
std::string typeName;
// read children
in >> typeName;
in.get();
if(typeName != "NULL") {
if(typeName == "Line") {
if (typeName != "NULL") {
if (typeName == "Line") {
child[0] = new Line(NULL);
child[1] = new Line(NULL);
};
if(typeName == "Triangle") {
if (typeName == "Triangle") {
child[0] = new Triangle(NULL);
child[1] = new Triangle(NULL);
};
if(typeName == "Tetrahedron") {
if (typeName == "Tetrahedron") {