Skip to content
Snippets Groups Projects
Commit 2a0239ea authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

Code refactoring.

parent 13579ff8
No related branches found
No related tags found
No related merge requests found
...@@ -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;
SerUtil::serialize(out, lineNo);
}
void Parameters::param::deserialize(std::istream &in)
{
in >> key; in.get();
in >> parameters; in.get();
in >> filename; in.get();
in >> funcName; in.get();
SerUtil::deserialize(in, lineNo);
}
} }
...@@ -31,10 +31,6 @@ ...@@ -31,10 +31,6 @@
namespace AMDiS { namespace AMDiS {
// ============================================================================
// ===== class Parameters =====================================================
// ============================================================================
/** \ingroup Common /** \ingroup Common
* \brief * \brief
* Many procedures need parameters, for example the maximal number of * Many procedures need parameters, for example the maximal number of
...@@ -71,9 +67,7 @@ namespace AMDiS { ...@@ -71,9 +67,7 @@ namespace AMDiS {
* argument flags, replacing macros by their definitions in the parameter * argument flags, replacing macros by their definitions in the parameter
* file and including files specified by \#include"...". * file and including files specified by \#include"...".
*/ */
static void init(int print, static void init(int print, std::string filename, const char *flags = NULL);
std::string filename,
const char *flags=NULL);
/** \brief /** \brief
* Reads all arguments which are provided to the program. The init filenames * Reads all arguments which are provided to the program. The init filenames
...@@ -182,37 +176,24 @@ namespace AMDiS { ...@@ -182,37 +176,24 @@ namespace AMDiS {
const char *format, const char *format,
...); ...);
/** \brief /// Like getGlobalParameter(flag, key, "%s", param->c_str()).
* Like getGlobalParameter(flag, key, "%s", param->c_str()). static int getGlobalParameter(int flag, const std::string& key, std::string *param);
*/
static int getGlobalParameter(int flag,
const std::string& key,
std::string *param);
/** \brief /// Prints all defined parameters to the message stream
* Prints all defined parameters to the message stream
*/
static void printParameters(); static void printParameters();
/** \brief /// Used by macro \ref GET_PARAMETER to generate infos about the calling function.
* Used by macro \ref GET_PARAMETER to generate infos about the calling static int initFuncName(const char *, const char *, int call_line);
* function.
*/
static int initFuncName(const char *,
const char *,
int call_line);
/** \brief /// Returns specified info level
* Returns specified info level static int getMsgInfo()
*/ {
static int getMsgInfo() {
return (singlett) ? singlett->msgInfo : 0; return (singlett) ? singlett->msgInfo : 0;
} }
/** \brief /// Returns specified wait value
* Returns specified wait value static int getMsgWait()
*/ {
static int getMsgWait() {
return (singlett) ? singlett->msgWait : 0; return (singlett) ? singlett->msgWait : 0;
} }
...@@ -224,43 +205,24 @@ namespace AMDiS { ...@@ -224,43 +205,24 @@ namespace AMDiS {
*/ */
static void save(const std::string file, int info); static void save(const std::string file, int info);
/** \brief /// Checks whether parameters are initialized. if not, call init()
* Checks whether parameters are initialized. if not, call init() static bool initialized()
*/ {
static bool initialized() {
return (singlett != NULL); return (singlett != NULL);
} }
static Parameters *getSingleton() { static Parameters *getSingleton()
{
return singlett; return singlett;
} }
static void clear(); static void clear();
// ===== Serializable implementation ===== /// Writes parameters to an output stream.
void serialize(std::ostream &out);
void serialize(std::ostream &out) { /// Reads parameters from an input stream.
out.write(reinterpret_cast<const char*>(&paramInfo), sizeof(int)); void deserialize(std::istream &in);
out.write(reinterpret_cast<const char*>(&msgInfo), sizeof(int));
out.write(reinterpret_cast<const char*>(&msgWait), sizeof(int));
int i, size = static_cast<int>(allParam.size());
out.write(reinterpret_cast<const char*>(&size), sizeof(int));
for(i = 0; i < size; i++) {
allParam[i].serialize(out);
}
}
void deserialize(std::istream &in) {
in.read(reinterpret_cast<char*>(&paramInfo), sizeof(int));
in.read(reinterpret_cast<char*>(&msgInfo), sizeof(int));
in.read(reinterpret_cast<char*>(&msgWait), sizeof(int));
int i, size;
in.read(reinterpret_cast<char*>(&size), sizeof(int));
allParam.resize(size);
for(i = 0; i < size; i++) {
allParam[i].deserialize(in);
}
}
private: private:
static Parameters * singlett; static Parameters * singlett;
...@@ -271,10 +233,7 @@ namespace AMDiS { ...@@ -271,10 +233,7 @@ namespace AMDiS {
static int param_call_line; static int param_call_line;
/// Used internally.
/** \brief
* Used internally.
*/
class param : public Serializable class param : public Serializable
{ {
public: public:
...@@ -300,27 +259,16 @@ namespace AMDiS { ...@@ -300,27 +259,16 @@ namespace AMDiS {
int operator==(const class param& aParam) const; int operator==(const class param& aParam) const;
int operator!=(const class param& aParam) const { int operator!=(const class param& aParam) const
return !(aParam==*this); {
return !(aParam == *this);
} }
// ===== Serializable implementation ===== /// Writes one parameter to an output stream.
void serialize(std::ostream &out);
void serialize(std::ostream &out) {
out << key << std::endl;
out << parameters << std::endl;
out << filename << std::endl;
out << funcName << std::endl;
out.write(reinterpret_cast<const char*>(&lineNo), sizeof(int));
}
void deserialize(std::istream &in) { /// Reads one parameter from an inputput stream.
in >> key; in.get(); void deserialize(std::istream &in);
in >> parameters; in.get();
in >> filename; in.get();
in >> funcName; in.get();
in.read(reinterpret_cast<char*>(&lineNo), sizeof(int));
}
public: public:
std::string key; std::string key;
...@@ -334,29 +282,30 @@ namespace AMDiS { ...@@ -334,29 +282,30 @@ namespace AMDiS {
std::string buffer; std::string buffer;
inline bool isBlankChar(const char s) { inline bool isBlankChar(const char s)
{
return (s == ' ' || s == '\t' || s == '\f' || s == '\r'); return (s == ' ' || s == '\t' || s == '\f' || s == '\r');
} }
const char *getNextWord(std::string *s) const; const char *getNextWord(std::string *s) const;
void read(const std::string& filename,const std::string& maxKey=""); void read(const std::string& filename,const std::string& maxKey = "");
const std::string& getActFile(const std::string& filename); const std::string& getActFile(const std::string& filename);
const std::string getKey(const std::string& s, const std::string getKey(const std::string& s,
int nLine, int nLine,
const std::string& filename); const std::string& filename);
const std::string getPar(const std::string& key, const std::string getPar(const std::string& key,
const std::string& s, const std::string& s,
int *nl, int *nl,
const std::string& fn); const std::string& fn);
void addParam(const std::string& key, void addParam(const std::string& key,
const std::string& parameter, const std::string& parameter,
const std::string& actfile, const std::string& actfile,
int nLine, int nLine,
const std::string& fname); const std::string& fname);
Parameters() Parameters()
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "FileWriter.h" #include "FileWriter.h"
#include "Parameters.h" #include "Parameters.h"
#include "AdaptInfo.h" #include "AdaptInfo.h"
#include "ProblemStatBase.h"
namespace AMDiS { namespace AMDiS {
......
...@@ -127,7 +127,7 @@ namespace AMDiS { ...@@ -127,7 +127,7 @@ namespace AMDiS {
out << fe->getMesh()->getName() << "\n"; out << fe->getMesh()->getName() << "\n";
int dim = fe->getMesh()->getDim(); int dim = fe->getMesh()->getDim();
out.write(reinterpret_cast<const char*>(&dim), sizeof(int)); SerUtil::serialize(out, dim);
fe->getMesh()->serialize(out); fe->getMesh()->serialize(out);
...@@ -135,8 +135,8 @@ namespace AMDiS { ...@@ -135,8 +135,8 @@ namespace AMDiS {
dim = fe->getBasisFcts()->getDim(); dim = fe->getBasisFcts()->getDim();
int degree = fe->getBasisFcts()->getDegree(); int degree = fe->getBasisFcts()->getDegree();
out << ((fe->getName() != "") ? fe->getName() : "noname") << "\n"; out << ((fe->getName() != "") ? fe->getName() : "noname") << "\n";
out.write(reinterpret_cast<const char*>(&dim), sizeof(int)); SerUtil::serialize(out, dim);
out.write(reinterpret_cast<const char*>(&degree), sizeof(int)); SerUtil::serialize(out, degree);
} }
/** \brief /** \brief
...@@ -149,7 +149,7 @@ namespace AMDiS { ...@@ -149,7 +149,7 @@ namespace AMDiS {
void serializeFeSpace(std::ofstream &out, std::vector<FiniteElemSpace*>& fe) void serializeFeSpace(std::ofstream &out, std::vector<FiniteElemSpace*>& fe)
{ {
int size = fe.size(); int size = fe.size();
out.write(reinterpret_cast<const char*>(&size), sizeof(int)); SerUtil::serialize(out, size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
// Check, if the pointer points to an fe space serialized before. // Check, if the pointer points to an fe space serialized before.
...@@ -161,7 +161,7 @@ namespace AMDiS { ...@@ -161,7 +161,7 @@ namespace AMDiS {
} }
} }
out.write(reinterpret_cast<const char*>(&found), sizeof(int)); SerUtil::serialize(out, found);
// Only in case this fe space was not serialized before, write it to the file. // Only in case this fe space was not serialized before, write it to the file.
if (found == -1) if (found == -1)
serializeFeSpace(out, fe[i]); serializeFeSpace(out, fe[i]);
...@@ -176,15 +176,14 @@ namespace AMDiS { ...@@ -176,15 +176,14 @@ namespace AMDiS {
in >> name; in >> name;
in.get(); in.get();
in.read(reinterpret_cast<char*>(&dim), sizeof(int)); SerUtil::deserialize(in, dim);
Mesh *mesh = new Mesh(name, dim); Mesh *mesh = new Mesh(name, dim);
mesh->deserialize(in); mesh->deserialize(in);
in >> name; in >> name;
in.get(); in.get();
in.read(reinterpret_cast<char*>(&dim), sizeof(int)); SerUtil::deserialize(in, dim);
in.read(reinterpret_cast<char*>(&degree), sizeof(int)); SerUtil::deserialize(in, degree);
*fe = FiniteElemSpace::provideFESpace(NULL, *fe = FiniteElemSpace::provideFESpace(NULL,
Lagrange::getLagrange(dim, degree), Lagrange::getLagrange(dim, degree),
mesh, mesh,
...@@ -195,17 +194,16 @@ namespace AMDiS { ...@@ -195,17 +194,16 @@ namespace AMDiS {
void deserializeFeSpace(std::ifstream &in, std::vector<FiniteElemSpace*>& fe) void deserializeFeSpace(std::ifstream &in, std::vector<FiniteElemSpace*>& fe)
{ {
int size; int size;
in.read(reinterpret_cast<char*>(&size), sizeof(int)); SerUtil::deserialize(in, size);
fe.resize(size); fe.resize(size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
int found; int found;
in.read(reinterpret_cast<char*>(&found), sizeof(int)); SerUtil::deserialize(in, found);
if (found == -1) { if (found == -1)
deserializeFeSpace(in, &(fe[i])); deserializeFeSpace(in, &(fe[i]));
} else { else
fe[i] = fe[found]; fe[i] = fe[found];
}
} }
} }
......
...@@ -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 {
...@@ -103,15 +104,15 @@ namespace AMDiS { ...@@ -103,15 +104,15 @@ namespace AMDiS {
void serialize(std::ostream& out) void serialize(std::ostream& out)
{ {
ElementData::serialize(out); ElementData::serialize(out);
out.write(reinterpret_cast<const char*>(&side), sizeof(int)); SerUtil::serialize(out, side);
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*>(&side), sizeof(int)); SerUtil::deserialize(in, side);
in.read(reinterpret_cast<char*>(&region), sizeof(int)); SerUtil::deserialize(in, region);
} }
inline void setSide(int s) inline void setSide(int s)
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "CreatorInterface.h" #include "CreatorInterface.h"
#include "Serializable.h" #include "Serializable.h"
#include "OpenMP.h" #include "OpenMP.h"
#include "Serializer.h"
namespace AMDiS { namespace AMDiS {
...@@ -242,7 +243,7 @@ namespace AMDiS { ...@@ -242,7 +243,7 @@ namespace AMDiS {
void serialize(std::ostream &out) void serialize(std::ostream &out)
{ {
int size = vectors.getSize(); int size = vectors.getSize();
out.write(reinterpret_cast<const char*>(&size), sizeof(int)); SerUtil::serialize(out, size);
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
vectors[i]->serialize(out); vectors[i]->serialize(out);
} }
...@@ -250,7 +251,7 @@ namespace AMDiS { ...@@ -250,7 +251,7 @@ namespace AMDiS {
void deserialize(std::istream &in) void deserialize(std::istream &in)
{ {
int size, oldSize = vectors.getSize(); int size, oldSize = vectors.getSize();
in.read(reinterpret_cast<char*>(&size), sizeof(int)); SerUtil::deserialize(in, size);
vectors.resize(size); vectors.resize(size);
for (int i = oldSize; i < size; i++) for (int i = oldSize; i < size; i++)
vectors[i] = new DOFVector<double>(feSpace[i], ""); vectors[i] = new DOFVector<double>(feSpace[i], "");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment