Commit 986197b6 authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

* Copy operator for meshes implemented

parent 68275e39
...@@ -23,7 +23,7 @@ namespace AMDiS { ...@@ -23,7 +23,7 @@ namespace AMDiS {
init(); init();
} }
DOFAdmin::DOFAdmin(Mesh* m,std::string aName) DOFAdmin::DOFAdmin(Mesh* m, std::string aName)
: name(aName), : name(aName),
mesh(m), mesh(m),
nrDOF(mesh->getDim(), NO_INIT), nrDOF(mesh->getDim(), NO_INIT),
...@@ -34,7 +34,11 @@ namespace AMDiS { ...@@ -34,7 +34,11 @@ namespace AMDiS {
void DOFAdmin::init() void DOFAdmin::init()
{ {
firstHole = size = usedCount = holeCount = sizeUsed = 0; firstHole = 0;
size = 0;
usedCount = 0;
holeCount = 0;
sizeUsed = 0;
dofFree.clear(); dofFree.clear();
} }
...@@ -75,6 +79,9 @@ namespace AMDiS { ...@@ -75,6 +79,9 @@ namespace AMDiS {
DOFAdmin::DOFAdmin(const DOFAdmin&) DOFAdmin::DOFAdmin(const DOFAdmin&)
{ {
FUNCNAME("DOFAdmin::DOFAdmin()");
ERROR_EXIT("TODO\n");
} }
void DOFAdmin::freeDOFIndex(int dof) { void DOFAdmin::freeDOFIndex(int dof) {
......
...@@ -152,14 +152,14 @@ namespace AMDiS { ...@@ -152,14 +152,14 @@ namespace AMDiS {
*/ */
std::list<DOFIndexedBase*>::iterator beginDOFIndexed() { std::list<DOFIndexedBase*>::iterator beginDOFIndexed() {
return dofIndexedList.begin(); return dofIndexedList.begin();
}; }
/** \brief /** \brief
* Returns an iterator to the end of \ref dofIndexedList * Returns an iterator to the end of \ref dofIndexedList
*/ */
std::list<DOFIndexedBase*>::iterator endDOFIndexed() { std::list<DOFIndexedBase*>::iterator endDOFIndexed() {
return dofIndexedList.end(); return dofIndexedList.end();
}; }
// ===== getting methods ====================================================== // ===== getting methods ======================================================
...@@ -172,38 +172,39 @@ namespace AMDiS { ...@@ -172,38 +172,39 @@ namespace AMDiS {
*/ */
inline const int getUsedSize() const { inline const int getUsedSize() const {
return sizeUsed; return sizeUsed;
}; }
/** \brief /** \brief
* Returns \ref size * Returns \ref size
*/ */
inline const int getSize() const { inline const int getSize() const {
return size; return size;
}; }
/** \brief /** \brief
* Returns \ref usedCount * Returns \ref usedCount
*/ */
inline const int getUsedDOFs() const { inline const int getUsedDOFs() const {
return usedCount; return usedCount;
}; }
/** \brief /** \brief
* Returns \ref holeCount * Returns \ref holeCount
*/ */
inline const int getHoleCount() const { inline const int getHoleCount() const {
return holeCount; return holeCount;
}; }
/** \brief /** \brief
* Returns \ref name * Returns \ref name
*/ */
inline const std::string& getName() const { inline const std::string& getName() const {
return name; return name;
}; }
/** \brief /** \brief
* Returns \ref nrDOF[i] * Returns \ref nrDOF[i], i.e., the number of dofs for the
* position i.
*/ */
inline const int getNumberOfDOFs(int i) const { inline const int getNumberOfDOFs(int i) const {
return nrDOF[i]; return nrDOF[i];
...@@ -214,7 +215,7 @@ namespace AMDiS { ...@@ -214,7 +215,7 @@ namespace AMDiS {
*/ */
inline const DimVec<int>& getNumberOfDOFs() const { inline const DimVec<int>& getNumberOfDOFs() const {
return nrDOF; return nrDOF;
}; }
/** \brief /** \brief
* Returns \ref nr0DOF[i] * Returns \ref nr0DOF[i]
...@@ -228,28 +229,28 @@ namespace AMDiS { ...@@ -228,28 +229,28 @@ namespace AMDiS {
*/ */
inline const DimVec<int>& getNumberOfPreDOFs() const { inline const DimVec<int>& getNumberOfPreDOFs() const {
return nr0DOF; return nr0DOF;
}; }
/** \brief /** \brief
* Returns \ref mesh * Returns \ref mesh
*/ */
inline const Mesh* getMesh() const { inline const Mesh* getMesh() const {
return mesh; return mesh;
}; }
/** \brief /** \brief
* Returns \ref dofFree, the array denoting DOFs to be either free or used. * Returns \ref dofFree, the array denoting DOFs to be either free or used.
*/ */
inline const std::vector<bool>& getDOFFree() const { inline const std::vector<bool>& getDOFFree() const {
return dofFree; return dofFree;
}; }
/** \brief /** \brief
* Returns if the given DOF is free. * Returns if the given DOF is free.
*/ */
inline const bool isDOFFree(int i) const { inline const bool isDOFFree(int i) const {
return dofFree[i]; return dofFree[i];
}; }
/** \} */ /** \} */
...@@ -262,7 +263,7 @@ namespace AMDiS { ...@@ -262,7 +263,7 @@ namespace AMDiS {
/** \brief /** \brief
* Sets \ref nrDOF[i] = v * Sets \ref nrDOF[i] = v
*/ */
void setNumberOfDOFs(int i,int v); void setNumberOfDOFs(int i, int v);
/** \brief /** \brief
* Sets \ref nr0DOF[i] = v * Sets \ref nr0DOF[i] = v
...@@ -274,14 +275,14 @@ namespace AMDiS { ...@@ -274,14 +275,14 @@ namespace AMDiS {
*/ */
inline void setName(const std::string& n) { inline void setName(const std::string& n) {
name = n; name = n;
}; }
/** \brief /** \brief
* Sets \ref mesh = m * Sets \ref mesh = m
*/ */
inline void setMesh(Mesh* m) { inline void setMesh(Mesh* m) {
mesh = m; mesh = m;
}; }
/** \} */ /** \} */
...@@ -350,7 +351,8 @@ namespace AMDiS { ...@@ -350,7 +351,8 @@ namespace AMDiS {
int sizeUsed; int sizeUsed;
/** \brief /** \brief
* dofs from THIS DOFAdmin * Number of dofs for each position, i.e., vertex,
* edge, ..., center, for this DOFAdmin.
*/ */
DimVec<int> nrDOF; DimVec<int> nrDOF;
......
...@@ -64,6 +64,72 @@ namespace AMDiS { ...@@ -64,6 +64,72 @@ namespace AMDiS {
} }
} }
Element* Element::cloneWithDOFs()
{
Element *el;
if (isLine()) {
el = NEW Line(mesh);
} else if (isTriangle()) {
el = NEW Triangle(mesh);
} else {
el = NEW Tetrahedron(mesh);
}
el->index = index;
el->mark = mark;
if (newCoord) {
WorldVector<double> *nc = NEW WorldVector<double>();
*nc = *newCoord;
el->newCoord = nc;
}
/* =========== And here we clone the DOFs =========== */
el->dof = GET_MEMORY(DegreeOfFreedom*, mesh->getNumberOfNodes());
int dim = mesh->getDim();
int j = 0;
for (int pos = 0; pos <= dim; pos++) {
GeoIndex position = INDEX_OF_DIM(pos, dim);
int ndof = 0;
for (int i = 0; i < mesh->getNumberOfDOFAdmin(); i++) {
ndof += mesh->getDOFAdmin(i).getNumberOfDOFs(position);
}
if (ndof > 0) {
for (int i = 0; i < mesh->getGeo(position); i++) {
if (dof[j] != NULL) {
if (Mesh::serializedDOFs[dof[j][0]] == NULL) {
el->dof[j] = GET_MEMORY(DegreeOfFreedom, ndof);
for (int k = 0; k < ndof; k++) {
el->dof[j][k] = dof[j][k];
}
Mesh::serializedDOFs[dof[j][0]] = el->dof[j];
} else {
el->dof[j] = Mesh::serializedDOFs[dof[j][0]];
}
} else {
el->dof[j] = NULL;
}
j++;
}
}
}
/* =========== And clone the children ============= */
if (child[0]) {
el->child[0] = child[0]->clone();
}
if (child[1]) {
el->child[1] = child[1]->clone();
}
return el;
}
/****************************************************************************/ /****************************************************************************/
/* ATTENTION: */ /* ATTENTION: */
/* new_dof_fct() destroys new_dof !!!!!!!!!! */ /* new_dof_fct() destroys new_dof !!!!!!!!!! */
...@@ -92,9 +158,8 @@ namespace AMDiS { ...@@ -92,9 +158,8 @@ namespace AMDiS {
void Element::newDOFFct1(const DOFAdmin* admin) void Element::newDOFFct1(const DOFAdmin* admin)
{ {
int i, j, k, n0, nd, nd0; int j, k, n0, nd, nd0;
DegreeOfFreedom *ldof; DegreeOfFreedom *ldof;
int vertices = mesh->getGeo(VERTEX); int vertices = mesh->getGeo(VERTEX);
int edges = mesh->getGeo(EDGE); int edges = mesh->getGeo(EDGE);
int faces = mesh->getGeo(FACE); int faces = mesh->getGeo(FACE);
...@@ -102,7 +167,7 @@ namespace AMDiS { ...@@ -102,7 +167,7 @@ namespace AMDiS {
if ((nd = admin->getNumberOfDOFs(VERTEX))) { if ((nd = admin->getNumberOfDOFs(VERTEX))) {
nd0 = admin->getNumberOfPreDOFs(VERTEX); nd0 = admin->getNumberOfPreDOFs(VERTEX);
n0 = admin->getMesh()->getNode(VERTEX); n0 = admin->getMesh()->getNode(VERTEX);
for (i = 0; i < vertices; i++) { for (int i = 0; i < vertices; i++) {
CHANGE_DOFS_1(this); CHANGE_DOFS_1(this);
} }
} }
...@@ -111,7 +176,7 @@ namespace AMDiS { ...@@ -111,7 +176,7 @@ namespace AMDiS {
if ((nd = admin->getNumberOfDOFs(EDGE))) { if ((nd = admin->getNumberOfDOFs(EDGE))) {
nd0 = admin->getNumberOfPreDOFs(EDGE); nd0 = admin->getNumberOfPreDOFs(EDGE);
n0 = admin->getMesh()->getNode(EDGE); n0 = admin->getMesh()->getNode(EDGE);
for (i = 0; i < edges; i++) { for (int i = 0; i < edges; i++) {
CHANGE_DOFS_1(this); CHANGE_DOFS_1(this);
} }
} }
...@@ -121,7 +186,7 @@ namespace AMDiS { ...@@ -121,7 +186,7 @@ namespace AMDiS {
if ((nd = admin->getNumberOfDOFs(FACE))) { if ((nd = admin->getNumberOfDOFs(FACE))) {
nd0 = admin->getNumberOfPreDOFs(FACE); nd0 = admin->getNumberOfPreDOFs(FACE);
n0 = admin->getMesh()->getNode(FACE); n0 = admin->getMesh()->getNode(FACE);
for (i = 0; i < faces; i++) { for (int i = 0; i < faces; i++) {
CHANGE_DOFS_1(this); CHANGE_DOFS_1(this);
} }
} }
...@@ -130,7 +195,7 @@ namespace AMDiS { ...@@ -130,7 +195,7 @@ namespace AMDiS {
if ((nd = admin->getNumberOfDOFs(CENTER))) { if ((nd = admin->getNumberOfDOFs(CENTER))) {
nd0 = admin->getNumberOfPreDOFs(CENTER); nd0 = admin->getNumberOfPreDOFs(CENTER);
n0 = admin->getMesh()->getNode(CENTER); n0 = admin->getMesh()->getNode(CENTER);
i = 0; /* only one center */ int i = 0; /* only one center */
CHANGE_DOFS_1(this); CHANGE_DOFS_1(this);
} }
} }
...@@ -138,9 +203,8 @@ namespace AMDiS { ...@@ -138,9 +203,8 @@ namespace AMDiS {
void Element::newDOFFct2(const DOFAdmin* admin) void Element::newDOFFct2(const DOFAdmin* admin)
{ {
int i, j, k, n0, nd, nd0; int i, j, k, n0, nd, nd0;
DegreeOfFreedom *ldof; DegreeOfFreedom *ldof;
int vertices = mesh->getGeo(VERTEX); int vertices = mesh->getGeo(VERTEX);
int edges = mesh->getGeo(EDGE); int edges = mesh->getGeo(EDGE);
int faces = mesh->getGeo(FACE); int faces = mesh->getGeo(FACE);
...@@ -191,13 +255,13 @@ namespace AMDiS { ...@@ -191,13 +255,13 @@ namespace AMDiS {
int Element::oppVertex(FixVec<DegreeOfFreedom*, DIMEN> pdof) const int Element::oppVertex(FixVec<DegreeOfFreedom*, DIMEN> pdof) const
{ {
int nv = 0, ov = 0; int nv = 0;
int ov = 0;
int vertices = mesh->getGeo(VERTEX); int vertices = mesh->getGeo(VERTEX);
int dim = mesh->getDim(); int dim = mesh->getDim();
for (int i = 0; i < vertices; i++) { for (int i = 0; i < vertices; i++) {
if (nv < i-1) if (nv < i - 1)
return(-1); return(-1);
for (int j = 0; j < dim; j++) { for (int j = 0; j < dim; j++) {
...@@ -225,10 +289,10 @@ namespace AMDiS { ...@@ -225,10 +289,10 @@ namespace AMDiS {
return ov; return ov;
break; break;
case 2: case 2:
return 3-ov; return 3 - ov;
break; break;
case 3: case 3:
return 6-ov; return 6 - ov;
break; break;
default: default:
ERROR_EXIT("invalid dim\n"); ERROR_EXIT("invalid dim\n");
...@@ -237,19 +301,19 @@ namespace AMDiS { ...@@ -237,19 +301,19 @@ namespace AMDiS {
} }
double Element::getNewCoord(int j) const { double Element::getNewCoord(int j) const {
if (j >=0 ) { if (j >= 0) {
TEST_EXIT_DBG(newCoord)("newCoord = NULL\n"); TEST_EXIT_DBG(newCoord)("newCoord = NULL\n");
return (*newCoord)[j]; return (*newCoord)[j];
} else { } else {
return (newCoord!=NULL); return (newCoord != NULL);
} }
} }
void Element::eraseNewCoord() { void Element::eraseNewCoord() {
if (newCoord!=NULL) { if (newCoord != NULL) {
DELETE newCoord; DELETE newCoord;
newCoord=NULL; newCoord = NULL;
}; }
} }
void Element::serialize(std::ostream &out) void Element::serialize(std::ostream &out)
...@@ -270,13 +334,11 @@ namespace AMDiS { ...@@ -270,13 +334,11 @@ namespace AMDiS {
out.write(reinterpret_cast<const char*>(&nodes), sizeof(int)); out.write(reinterpret_cast<const char*>(&nodes), sizeof(int));
for (int pos = 0; pos <= dim; pos++) { for (int pos = 0; pos <= dim; pos++) {
GeoIndex position = INDEX_OF_DIM(pos ,dim); GeoIndex position = INDEX_OF_DIM(pos, dim);
int ndof = 0; int ndof = 0;
for (int i = 0; i < mesh->getNumberOfDOFAdmin(); i++) { for (int i = 0; i < mesh->getNumberOfDOFAdmin(); i++) {
const DOFAdmin *localAdmin = &mesh->getDOFAdmin(i); ndof += mesh->getDOFAdmin(i).getNumberOfDOFs(position);
TEST_EXIT_DBG(localAdmin)("no admin[%d]\n", i);
ndof += localAdmin->getNumberOfDOFs(position);
} }
if (ndof > 0) { if (ndof > 0) {
...@@ -285,8 +347,7 @@ namespace AMDiS { ...@@ -285,8 +347,7 @@ namespace AMDiS {
if (Mesh::serializedDOFs[dof[j][0]] == NULL) { if (Mesh::serializedDOFs[dof[j][0]] == NULL) {
Mesh::serializedDOFs[dof[j][0]] = dof[j]; Mesh::serializedDOFs[dof[j][0]] = dof[j];
out.write(reinterpret_cast<const char*>(&ndof), sizeof(int)); out.write(reinterpret_cast<const char*>(&ndof), sizeof(int));
out.write(reinterpret_cast<const char*>(dof[j]), out.write(reinterpret_cast<const char*>(dof[j]), ndof * sizeof(DegreeOfFreedom));
ndof * sizeof(DegreeOfFreedom));
} else { } else {
int minusOne = -1; int minusOne = -1;
out.write(reinterpret_cast<const char*>(&minusOne), sizeof(int)); out.write(reinterpret_cast<const char*>(&minusOne), sizeof(int));
...@@ -334,17 +395,17 @@ namespace AMDiS { ...@@ -334,17 +395,17 @@ namespace AMDiS {
if (typeName != "NULL") { if (typeName != "NULL") {
if (typeName == "Line") { if (typeName == "Line") {
child[0] = new Line(NULL); child[0] = NEW Line(NULL);
child[1] = new Line(NULL); child[1] = NEW Line(NULL);
}; }
if (typeName == "Triangle") { if (typeName == "Triangle") {
child[0] = new Triangle(NULL); child[0] = NEW Triangle(NULL);
child[1] = new Triangle(NULL); child[1] = NEW Triangle(NULL);
}; }
if (typeName == "Tetrahedron") { if (typeName == "Tetrahedron") {
child[0] = new Tetrahedron(NULL); child[0] = NEW Tetrahedron(NULL);
child[1] = new Tetrahedron(NULL); child[1] = NEW Tetrahedron(NULL);
}; }
child[0]->deserialize(in); child[0]->deserialize(in);
child[1]->deserialize(in); child[1]->deserialize(in);
} else { } else {
...@@ -357,22 +418,21 @@ namespace AMDiS { ...@@ -357,22 +418,21 @@ namespace AMDiS {
dof = GET_MEMORY(DegreeOfFreedom*, nodes); dof = GET_MEMORY(DegreeOfFreedom*, nodes);
int i; for (int i = 0; i < nodes; i++) {
for(i = 0; i < nodes; i++) {
int dofs; int dofs;
in.read(reinterpret_cast<char*>(&dofs), sizeof(int)); in.read(reinterpret_cast<char*>(&dofs), sizeof(int));
if(dofs) { if (dofs) {
if(dofs != -1) { if (dofs != -1) {
dof[i] = GET_MEMORY(DegreeOfFreedom, dofs); dof[i] = GET_MEMORY(DegreeOfFreedom, dofs);
in.read(reinterpret_cast<char*>(dof[i]), dofs * sizeof(DegreeOfFreedom)); in.read(reinterpret_cast<char*>(dof[i]), dofs * sizeof(DegreeOfFreedom));
if(Mesh::serializedDOFs[dof[i][0]] != NULL) { if (Mesh::serializedDOFs[dof[i][0]] != NULL) {
//WARNING("christina -> dofs already deserialized\n");
DegreeOfFreedom *dofPtr = Mesh::serializedDOFs[dof[i][0]]; DegreeOfFreedom *dofPtr = Mesh::serializedDOFs[dof[i][0]];
FREE_MEMORY(dof[i], DegreeOfFreedom, dofs); FREE_MEMORY(dof[i], DegreeOfFreedom, dofs);
dof[i] = dofPtr; dof[i] = dofPtr;
} else {
Mesh::serializedDOFs[dof[i][0]] = dof[i];
} }
Mesh::serializedDOFs[dof[i][0]] = dof[i];
} else { } else {
DegreeOfFreedom index; DegreeOfFreedom index;
in.read(reinterpret_cast<char*>(&index), sizeof(DegreeOfFreedom)); in.read(reinterpret_cast<char*>(&index), sizeof(DegreeOfFreedom));
...@@ -393,8 +453,8 @@ namespace AMDiS { ...@@ -393,8 +453,8 @@ namespace AMDiS {
in >> typeName; in >> typeName;
in.get(); in.get();
if(typeName != "NULL") { if (typeName != "NULL") {
if(typeName == "WorldVector") { if (typeName == "WorldVector") {