Am Montag, 13. Mai 2022, finden Wartungsarbeiten am Gitlab-Server (Update auf neue Version statt). Der Dienst wird daher am Montag für einige Zeit nicht verfügbar sein.
On Monday, May 13th 2022, the Gitlab server will be updated. The service will therefore not be accessible for some time on Monday.

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

Code refactoring.

parent 13579ff8
......@@ -24,6 +24,7 @@
#include "ElementData.h"
#include "FixVec.h"
#include "Serializer.h"
namespace AMDiS {
......@@ -92,13 +93,13 @@ namespace AMDiS {
void serialize(std::ostream& out)
{
ElementData::serialize(out);
out.write(reinterpret_cast<const char*>(&region), sizeof(int));
SerUtil::serialize(out, region);
}
void deserialize(std::istream& in)
{
ElementData::deserialize(in);
in.read(reinterpret_cast<char*>(&region), sizeof(int));
SerUtil::deserialize(in, region);
}
inline void setRegion(int r)
......
#include "LeafData.h"
#include "Element.h"
#include "Mesh.h"
#include "Serializer.h"
namespace AMDiS {
......@@ -42,6 +43,18 @@ namespace AMDiS {
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,
Element* child1,
Element* child2,
......@@ -65,8 +78,35 @@ namespace AMDiS {
TEST_EXIT_DBG(test)("couldn't delete LeafDataEstimatableVec at otherChild");
parent->setElementData(new LeafDataEstimatableVec(parent->getElementData()));
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,
Element* child1,
Element* child2,
......@@ -90,6 +130,18 @@ namespace AMDiS {
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,
Element* child1,
Element* child2,
......@@ -112,6 +164,33 @@ namespace AMDiS {
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,
Element* child1,
Element* child2,
......@@ -176,6 +255,27 @@ namespace AMDiS {
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)
{
periodicMode = rhs.periodicMode;
......@@ -184,17 +284,14 @@ namespace AMDiS {
if (rhs.periodicCoords) {
int dim = rhs.periodicCoords->getSize() - 1;
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];
}
} else {
periodicCoords = NULL;
}
}
LeafDataPeriodic::PeriodicInfo::PeriodicInfo(int mode,
BoundaryType t,
int side,
LeafDataPeriodic::PeriodicInfo::PeriodicInfo(int mode, BoundaryType t, int side,
const DimVec<WorldVector<double> > *coords)
: periodicMode(mode),
type(t),
......@@ -204,9 +301,44 @@ namespace AMDiS {
if (coords) {
int dim = coords->getSize() - 1;
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];
}
}
}
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 @@
#include "ElementData.h"
#include "Boundary.h"
namespace AMDiS {
class LeafDataEstimatableInterface
......@@ -119,17 +118,9 @@ namespace AMDiS {
return ESTIMATABLE;
}
void serialize(std::ostream& out)
{
ElementData::serialize(out);
out.write(reinterpret_cast<const char*>(&errorEstimate), sizeof(double));
}
void serialize(std::ostream& out);
void deserialize(std::istream& in)
{
ElementData::deserialize(in);
in.read(reinterpret_cast<char*>(&errorEstimate), sizeof(double));
}
void deserialize(std::istream& in);
private:
double errorEstimate;
......@@ -199,31 +190,9 @@ namespace AMDiS {
return newObj;
}
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 serialize(std::ostream& out);
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;
}
}
void deserialize(std::istream& in);
std::string getTypeName() const
{
......@@ -293,7 +262,8 @@ namespace AMDiS {
int elTypeParent);
/// Implements ElementData::clone().
inline ElementData *clone() const {
inline ElementData *clone() const
{
// create new estimatable leaf data
LeafDataCoarsenable *newObj = new LeafDataCoarsenable(NULL);
......@@ -316,23 +286,17 @@ namespace AMDiS {
return coarseningError;
}
void serialize(std::ostream& out)
{
ElementData::serialize(out);
out.write(reinterpret_cast<const char*>(&coarseningError), sizeof(double));
}
void serialize(std::ostream& out);
void deserialize(std::istream& in)
{
ElementData::deserialize(in);
in.read(reinterpret_cast<char*>(&coarseningError), sizeof(double));
}
void deserialize(std::istream& in);
std::string getTypeName() const {
std::string getTypeName() const
{
return "LeafDataCoarsenable";
}
inline const int getTypeID() const {
inline const int getTypeID() const
{
return COARSENABLE;
}
......@@ -407,31 +371,9 @@ namespace AMDiS {
return coarseningError[index];
}
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 serialize(std::ostream& out);
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;
}
}
void deserialize(std::istream& in);
std::string getTypeName() const
{
......@@ -489,41 +431,9 @@ namespace AMDiS {
PeriodicInfo(const PeriodicInfo &rhs);
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));
void serialize(std::ostream &out);
int size;
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);
}
}
void deserialize(std::istream &in);
int periodicMode;
......@@ -565,26 +475,9 @@ namespace AMDiS {
return periodicInfoList;
}
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 serialize(std::ostream& out);
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);
}
void deserialize(std::istream& in);
std::string getTypeName() const
{
......@@ -596,9 +489,7 @@ namespace AMDiS {
return PERIODIC;
}
bool refineElementData(Element* parent,
Element* child1,
Element* child2,
bool refineElementData(Element* parent, Element* child1, Element* child2,
int elType);
private:
......
#include "Parameters.h"
#include <fstream>
#include <sstream>
#include <algorithm>
......@@ -8,6 +7,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "Parameters.h"
#include "Serializer.h"
namespace AMDiS {
......@@ -752,8 +753,50 @@ namespace AMDiS {
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;
}
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 @@
namespace AMDiS {
// ============================================================================
// ===== class Parameters =====================================================
// ============================================================================
/** \ingroup Common
* \brief
* Many procedures need parameters, for example the maximal number of
......@@ -71,9 +67,7 @@ namespace AMDiS {
* argument flags, replacing macros by their definitions in the parameter
* file and including files specified by \#include"...".
*/
static void init(int print,
std::string filename,
const char *flags=NULL);
static void init(int print, std::string filename, const char *flags = NULL);
/** \brief
* Reads all arguments which are provided to the program. The init filenames
......@@ -182,37 +176,24 @@ namespace AMDiS {
const char *format,
...);
/** \brief
* Like getGlobalParameter(flag, key, "%s", param->c_str()).
*/
static int getGlobalParameter(int flag,
const std::string& key,
std::string *param);
/// Like getGlobalParameter(flag, key, "%s", param->c_str()).
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();
/** \brief
* Used by macro \ref GET_PARAMETER to generate infos about the calling
* function.
*/
static int initFuncName(const char *,
const char *,
int call_line);
/// Used by macro \ref GET_PARAMETER to generate infos about the calling function.
static int initFuncName(const char *, const char *, int call_line);
/** \brief
* Returns specified info level
*/
static int getMsgInfo() {
/// Returns specified info level
static int getMsgInfo()
{
return (singlett) ? singlett->msgInfo : 0;
}
/** \brief
* Returns specified wait value
*/
static int getMsgWait() {
/// Returns specified wait value
static int getMsgWait()
{
return (singlett) ? singlett->msgWait : 0;
}
......@@ -224,43 +205,24 @@ namespace AMDiS {
*/
static void save(const std::string file, int info);
/** \brief
* Checks whether parameters are initialized. if not, call init()
*/
static bool initialized() {
/// Checks whether parameters are initialized. if not, call init()
static bool initialized()
{
return (singlett != NULL);
}
static Parameters *getSingleton() {
static Parameters *getSingleton()
{
return singlett;
}
static void clear();
// ===== Serializable implementation =====
/// Writes parameters to an output stream.
void serialize(std::ostream &out);
void serialize(std::ostream &out) {
out.write(reinterpret_cast<const char*>(&paramInfo), sizeof(int));
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());