Commit 2a0239ea authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

Code refactoring.

parent 13579ff8
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "ElementData.h" #include "ElementData.h"
#include "FixVec.h" #include "FixVec.h"
#include "Serializer.h"
namespace AMDiS { namespace AMDiS {
...@@ -92,13 +93,13 @@ namespace AMDiS { ...@@ -92,13 +93,13 @@ namespace AMDiS {
void serialize(std::ostream& out) void serialize(std::ostream& out)
{ {
ElementData::serialize(out); ElementData::serialize(out);
out.write(reinterpret_cast<const char*>(&region), sizeof(int)); SerUtil::serialize(out, region);
} }
void deserialize(std::istream& in) void deserialize(std::istream& in)
{ {
ElementData::deserialize(in); ElementData::deserialize(in);
in.read(reinterpret_cast<char*>(&region), sizeof(int)); SerUtil::deserialize(in, region);
} }
inline void setRegion(int r) inline void setRegion(int r)
......
#include "LeafData.h" #include "LeafData.h"
#include "Element.h" #include "Element.h"
#include "Mesh.h" #include "Mesh.h"
#include "Serializer.h"
namespace AMDiS { namespace AMDiS {
...@@ -42,6 +43,18 @@ namespace AMDiS { ...@@ -42,6 +43,18 @@ namespace AMDiS {
ElementData::coarsenElementData(parent, thisChild, otherChild, elTypeParent); ElementData::coarsenElementData(parent, thisChild, otherChild, elTypeParent);
} }
void LeafDataEstimatable::serialize(std::ostream& out)
{
ElementData::serialize(out);
SerUtil::serialize(out, errorEstimate);
}
void LeafDataEstimatable::deserialize(std::istream& in)
{
ElementData::deserialize(in);
SerUtil::deserialize(in, errorEstimate);
}
bool LeafDataEstimatableVec::refineElementData(Element* parent, bool LeafDataEstimatableVec::refineElementData(Element* parent,
Element* child1, Element* child1,
Element* child2, Element* child2,
...@@ -65,8 +78,35 @@ namespace AMDiS { ...@@ -65,8 +78,35 @@ namespace AMDiS {
TEST_EXIT_DBG(test)("couldn't delete LeafDataEstimatableVec at otherChild"); TEST_EXIT_DBG(test)("couldn't delete LeafDataEstimatableVec at otherChild");
parent->setElementData(new LeafDataEstimatableVec(parent->getElementData())); parent->setElementData(new LeafDataEstimatableVec(parent->getElementData()));
ElementData::coarsenElementData(parent, thisChild, otherChild, elTypeParent); ElementData::coarsenElementData(parent, thisChild, otherChild, elTypeParent);
} }
void LeafDataEstimatableVec::serialize(std::ostream& out)
{
ElementData::serialize(out);
unsigned int size = errorEstimate.size();
SerUtil::serialize(out, size);
for (std::map<int, double>::iterator it = errorEstimate.begin();
it != errorEstimate.end(); ++it) {
SerUtil::serialize(out, it->first);
SerUtil::serialize(out, it->second);
}
}
void LeafDataEstimatableVec::deserialize(std::istream& in)
{
ElementData::deserialize(in);
unsigned size;
SerUtil::deserialize(in, size);
for (unsigned int i = 0; i < size; i++) {
int index;
double estimate;
SerUtil::deserialize(in, index);
SerUtil::deserialize(in, estimate);
errorEstimate[index] = estimate;
}
}
bool LeafDataCoarsenable::refineElementData(Element* parent, bool LeafDataCoarsenable::refineElementData(Element* parent,
Element* child1, Element* child1,
Element* child2, Element* child2,
...@@ -90,6 +130,18 @@ namespace AMDiS { ...@@ -90,6 +130,18 @@ namespace AMDiS {
ElementData::coarsenElementData(parent, thisChild, otherChild, elTypeParent); ElementData::coarsenElementData(parent, thisChild, otherChild, elTypeParent);
} }
void LeafDataCoarsenable::serialize(std::ostream& out)
{
ElementData::serialize(out);
SerUtil::serialize(out, coarseningError);
}
void LeafDataCoarsenable::deserialize(std::istream& in)
{
ElementData::deserialize(in);
SerUtil::deserialize(in, coarseningError);
}
bool LeafDataCoarsenableVec::refineElementData(Element* parent, bool LeafDataCoarsenableVec::refineElementData(Element* parent,
Element* child1, Element* child1,
Element* child2, Element* child2,
...@@ -112,6 +164,33 @@ namespace AMDiS { ...@@ -112,6 +164,33 @@ namespace AMDiS {
ElementData::coarsenElementData(parent, thisChild, otherChild, elTypeParent); ElementData::coarsenElementData(parent, thisChild, otherChild, elTypeParent);
} }
void LeafDataCoarsenableVec::serialize(std::ostream& out)
{
ElementData::serialize(out);
unsigned int size = coarseningError.size();
SerUtil::serialize(out, size);
for (std::map<int, double>::iterator it = coarseningError.begin();
it != coarseningError.end(); ++it) {
SerUtil::serialize(out, it->first);
SerUtil::serialize(out, it->second);
}
}
void LeafDataCoarsenableVec::deserialize(std::istream& in)
{
ElementData::deserialize(in);
unsigned int size;
SerUtil::deserialize(in, size);
for (unsigned int i = 0; i < size; i++) {
int index;
double estimate;
SerUtil::deserialize(in, index);
SerUtil::deserialize(in, estimate);
coarseningError[index] = estimate;
}
}
bool LeafDataPeriodic::refineElementData(Element* parent, bool LeafDataPeriodic::refineElementData(Element* parent,
Element* child1, Element* child1,
Element* child2, Element* child2,
...@@ -176,6 +255,27 @@ namespace AMDiS { ...@@ -176,6 +255,27 @@ namespace AMDiS {
return false; return false;
} }
void LeafDataPeriodic::serialize(std::ostream& out)
{
ElementData::serialize(out);
unsigned int size = periodicInfoList.size();
SerUtil::serialize(out, size);
for (std::list<PeriodicInfo>::iterator it = periodicInfoList.begin();
it != periodicInfoList.end(); ++it)
it->serialize(out);
}
void LeafDataPeriodic::deserialize(std::istream& in)
{
ElementData::deserialize(in);
unsigned int size;
SerUtil::deserialize(in, size);
periodicInfoList.resize(size);
for (std::list<PeriodicInfo>::iterator it = periodicInfoList.begin();
it != periodicInfoList.end(); ++it)
it->deserialize(in);
}
LeafDataPeriodic::PeriodicInfo::PeriodicInfo(const PeriodicInfo &rhs) LeafDataPeriodic::PeriodicInfo::PeriodicInfo(const PeriodicInfo &rhs)
{ {
periodicMode = rhs.periodicMode; periodicMode = rhs.periodicMode;
...@@ -184,17 +284,14 @@ namespace AMDiS { ...@@ -184,17 +284,14 @@ namespace AMDiS {
if (rhs.periodicCoords) { if (rhs.periodicCoords) {
int dim = rhs.periodicCoords->getSize() - 1; int dim = rhs.periodicCoords->getSize() - 1;
periodicCoords = new DimVec<WorldVector<double> >(dim, NO_INIT); periodicCoords = new DimVec<WorldVector<double> >(dim, NO_INIT);
for (int i = 0; i < dim + 1; i++) { for (int i = 0; i < dim + 1; i++)
(*periodicCoords)[i] = (*(rhs.periodicCoords))[i]; (*periodicCoords)[i] = (*(rhs.periodicCoords))[i];
}
} else { } else {
periodicCoords = NULL; periodicCoords = NULL;
} }
} }
LeafDataPeriodic::PeriodicInfo::PeriodicInfo(int mode, LeafDataPeriodic::PeriodicInfo::PeriodicInfo(int mode, BoundaryType t, int side,
BoundaryType t,
int side,
const DimVec<WorldVector<double> > *coords) const DimVec<WorldVector<double> > *coords)
: periodicMode(mode), : periodicMode(mode),
type(t), type(t),
...@@ -204,9 +301,44 @@ namespace AMDiS { ...@@ -204,9 +301,44 @@ namespace AMDiS {
if (coords) { if (coords) {
int dim = coords->getSize() - 1; int dim = coords->getSize() - 1;
periodicCoords = new DimVec<WorldVector<double> >(dim, NO_INIT); periodicCoords = new DimVec<WorldVector<double> >(dim, NO_INIT);
for (int i = 0; i < dim + 1; i++) { for (int i = 0; i < dim + 1; i++)
(*periodicCoords)[i] = (*coords)[i]; (*periodicCoords)[i] = (*coords)[i];
}
} }
} }
void LeafDataPeriodic::PeriodicInfo::serialize(std::ostream &out)
{
SerUtil::serialize(out, periodicMode);
SerUtil::serialize(out, type);
SerUtil::serialize(out, elementSide);
if (periodicCoords) {
int size = periodicCoords->getSize();
SerUtil::serialize(out, size);
for (int i = 0; i < size; i++)
(*periodicCoords)[i].serialize(out);
} else {
int size = 0;
SerUtil::serialize(out, size);
}
}
void LeafDataPeriodic::PeriodicInfo::deserialize(std::istream &in)
{
SerUtil::deserialize(in, periodicMode);
SerUtil::deserialize(in, type);
SerUtil::deserialize(in, elementSide);
int size;
SerUtil::deserialize(in, size);
if (periodicCoords)
delete periodicCoords;
if (size == 0) {
periodicCoords = NULL;
} else {
periodicCoords = new DimVec<WorldVector<double> >(size-1, NO_INIT);
for (int i = 0; i < size; i++)
(*periodicCoords)[i].deserialize(in);
}
}
} }
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "ElementData.h" #include "ElementData.h"
#include "Boundary.h" #include "Boundary.h"
namespace AMDiS { namespace AMDiS {
class LeafDataEstimatableInterface class LeafDataEstimatableInterface
...@@ -119,17 +118,9 @@ namespace AMDiS { ...@@ -119,17 +118,9 @@ namespace AMDiS {
return ESTIMATABLE; return ESTIMATABLE;
} }
void serialize(std::ostream& out) void serialize(std::ostream& out);
{
ElementData::serialize(out);
out.write(reinterpret_cast<const char*>(&errorEstimate), sizeof(double));
}
void deserialize(std::istream& in) void deserialize(std::istream& in);
{
ElementData::deserialize(in);
in.read(reinterpret_cast<char*>(&errorEstimate), sizeof(double));
}
private: private:
double errorEstimate; double errorEstimate;
...@@ -199,31 +190,9 @@ namespace AMDiS { ...@@ -199,31 +190,9 @@ namespace AMDiS {
return newObj; return newObj;
} }
void serialize(std::ostream& out) void serialize(std::ostream& out);
{
ElementData::serialize(out);
unsigned int size = errorEstimate.size();
out.write(reinterpret_cast<const char*>(&size), sizeof(unsigned int));
std::map<int, double>::iterator it;
for (it = errorEstimate.begin(); it != errorEstimate.end(); ++it) {
out.write(reinterpret_cast<const char*>(&(it->first)), sizeof(int));
out.write(reinterpret_cast<const char*>(&(it->second)), sizeof(double));
}
}
void deserialize(std::istream& in) void deserialize(std::istream& in);
{
ElementData::deserialize(in);
unsigned size;
in.read(reinterpret_cast<char*>(&size), sizeof(unsigned int));
for (unsigned int i = 0; i < size; i++) {
int index;
double estimate;
in.read(reinterpret_cast<char*>(&index), sizeof(int));
in.read(reinterpret_cast<char*>(&estimate), sizeof(double));
errorEstimate[index] = estimate;
}
}
std::string getTypeName() const std::string getTypeName() const
{ {
...@@ -293,7 +262,8 @@ namespace AMDiS { ...@@ -293,7 +262,8 @@ namespace AMDiS {
int elTypeParent); int elTypeParent);
/// Implements ElementData::clone(). /// Implements ElementData::clone().
inline ElementData *clone() const { inline ElementData *clone() const
{
// create new estimatable leaf data // create new estimatable leaf data
LeafDataCoarsenable *newObj = new LeafDataCoarsenable(NULL); LeafDataCoarsenable *newObj = new LeafDataCoarsenable(NULL);
...@@ -316,23 +286,17 @@ namespace AMDiS { ...@@ -316,23 +286,17 @@ namespace AMDiS {
return coarseningError; return coarseningError;
} }
void serialize(std::ostream& out) void serialize(std::ostream& out);
{
ElementData::serialize(out);
out.write(reinterpret_cast<const char*>(&coarseningError), sizeof(double));
}
void deserialize(std::istream& in) void deserialize(std::istream& in);
{
ElementData::deserialize(in);
in.read(reinterpret_cast<char*>(&coarseningError), sizeof(double));
}
std::string getTypeName() const { std::string getTypeName() const
{
return "LeafDataCoarsenable"; return "LeafDataCoarsenable";
} }
inline const int getTypeID() const { inline const int getTypeID() const
{
return COARSENABLE; return COARSENABLE;
} }
...@@ -407,31 +371,9 @@ namespace AMDiS { ...@@ -407,31 +371,9 @@ namespace AMDiS {
return coarseningError[index]; return coarseningError[index];
} }
void serialize(std::ostream& out) void serialize(std::ostream& out);
{
ElementData::serialize(out);
unsigned int size = coarseningError.size();
out.write(reinterpret_cast<const char*>(&size), sizeof(unsigned int));
std::map<int, double>::iterator it;
for (it = coarseningError.begin(); it != coarseningError.end(); ++it) {
out.write(reinterpret_cast<const char*>(&(it->first)), sizeof(int));
out.write(reinterpret_cast<const char*>(&(it->second)), sizeof(double));
}
}
void deserialize(std::istream& in) void deserialize(std::istream& in);
{
ElementData::deserialize(in);
unsigned int size;
in.read(reinterpret_cast<char*>(&size), sizeof(unsigned int));
for (unsigned int i = 0; i < size; i++) {
int index;
double estimate;
in.read(reinterpret_cast<char*>(&index), sizeof(int));
in.read(reinterpret_cast<char*>(&estimate), sizeof(double));
coarseningError[index] = estimate;
}
}
std::string getTypeName() const std::string getTypeName() const
{ {
...@@ -489,41 +431,9 @@ namespace AMDiS { ...@@ -489,41 +431,9 @@ namespace AMDiS {
PeriodicInfo(const PeriodicInfo &rhs); PeriodicInfo(const PeriodicInfo &rhs);
void serialize(std::ostream &out) void serialize(std::ostream &out);
{
out.write(reinterpret_cast<const char*>(&periodicMode), sizeof(int));
out.write(reinterpret_cast<const char*>(&type), sizeof(BoundaryType));
out.write(reinterpret_cast<const char*>(&elementSide), sizeof(int));
if (periodicCoords) {
int size = periodicCoords->getSize();
out.write(reinterpret_cast<const char*>(&size), sizeof(int));
for (int i = 0; i < size; i++) {
(*periodicCoords)[i].serialize(out);
}
} else {
int size = 0;
out.write(reinterpret_cast<const char*>(&size), sizeof(int));
}
}
void deserialize(std::istream &in)
{
in.read(reinterpret_cast<char*>(&periodicMode), sizeof(int));
in.read(reinterpret_cast<char*>(&type), sizeof(BoundaryType));
in.read(reinterpret_cast<char*>(&elementSide), sizeof(int));
int size; void deserialize(std::istream &in);
in.read(reinterpret_cast<char*>(&size), sizeof(int));
if (periodicCoords)
delete periodicCoords;
if (size == 0) {
periodicCoords = NULL;
} else {
periodicCoords = new DimVec<WorldVector<double> >(size-1, NO_INIT);
for (int i = 0; i < size; i++)
(*periodicCoords)[i].deserialize(in);
}
}
int periodicMode; int periodicMode;
...@@ -565,26 +475,9 @@ namespace AMDiS { ...@@ -565,26 +475,9 @@ namespace AMDiS {
return periodicInfoList; return periodicInfoList;
} }
void serialize(std::ostream& out) void serialize(std::ostream& out);
{
ElementData::serialize(out);
unsigned int size = periodicInfoList.size();
out.write(reinterpret_cast<const char*>(&size), sizeof(unsigned int));
std::list<PeriodicInfo>::iterator it;
for (it = periodicInfoList.begin(); it != periodicInfoList.end(); ++it)
it->serialize(out);
}
void deserialize(std::istream& in) void deserialize(std::istream& in);
{
ElementData::deserialize(in);
unsigned int size;
in.read(reinterpret_cast<char*>(&size), sizeof(unsigned int));
periodicInfoList.resize(size);
std::list<PeriodicInfo>::iterator it;
for (it = periodicInfoList.begin(); it != periodicInfoList.end(); ++it)
it->deserialize(in);
}
std::string getTypeName() const std::string getTypeName() const
{ {
...@@ -596,9 +489,7 @@ namespace AMDiS { ...@@ -596,9 +489,7 @@ namespace AMDiS {
return PERIODIC; return PERIODIC;
} }
bool refineElementData(Element* parent, bool refineElementData(Element* parent, Element* child1, Element* child2,
Element* child1,
Element* child2,
int elType); int elType);
private: private:
......
#include "Parameters.h"
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
...@@ -8,6 +7,8 @@ ...@@ -8,6 +7,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include "Parameters.h"
#include "Serializer.h"
namespace AMDiS { namespace AMDiS {
...@@ -752,8 +753,50 @@ namespace AMDiS { ...@@ -752,8 +753,50 @@ namespace AMDiS {
delete singlett; delete singlett;
} }
int Parameters::param::operator==(const param& aParam)const{ void Parameters::serialize(std::ostream &out)
{
SerUtil::serialize(out, paramInfo);
SerUtil::serialize(out, msgInfo);
SerUtil::serialize(out, msgWait);
int size = static_cast<int>(allParam.size());
SerUtil::serialize(out, size);
for (int i = 0; i < size; i++)
allParam[i].serialize(out);
}
void Parameters::deserialize(std::istream &in)
{
SerUtil::deserialize(in, paramInfo);
SerUtil::deserialize(in, msgInfo);
SerUtil::deserialize(in, msgWait);
int size;
SerUtil::deserialize(in, size);
allParam.resize(size);
for (int i = 0; i < size; i++)
allParam[i].deserialize(in);
}
int Parameters::param::operator==(const param& aParam) const
{
return key == aParam.key; return key == aParam.key;
} }
void Parameters::param::serialize(std::ostream &out)
{
out << key << std::endl;
out << parameters << std::endl;
out << filename << std::endl;
out << funcName << std::endl;