Commit 5b211985 authored by Praetorius, Simon's avatar Praetorius, Simon

DOFSerializer cleaned up

parent 73bc0569
...@@ -7,34 +7,38 @@ ...@@ -7,34 +7,38 @@
#include "Traverse.h" #include "Traverse.h"
namespace AMDiS namespace AMDiS
{ {
// satre values of DOFVector on all macro elements to internal container // store values of DOFVector on all macro elements to internal container
void DOFSerializer::gather(DOFVector<double> const* vec, std::vector<double>& values) void DOFSerializer::gather(DOFVector<double> const* vec, std::vector<double>& values)
{ {
std::fill(visited_.begin(), visited_.end(), false); std::fill(visited_.begin(), visited_.end(), false);
values.clear(); values.clear();
values.reserve(numValues_);
for (auto* macroEl : mesh_->getMacroElements()) for (auto* macroEl : mesh_->getMacroElements())
gather(macroEl->getIndex(), vec, values, false); gather(macroEl->getIndex(), vec, values, false);
numValues_ = values.size();
} }
// satre values of DOFVector on macro element `macroIndex` to internal container // store values of DOFVector on macro element `macroIndex` to internal container
void DOFSerializer::gather(int macroIndex, DOFVector<double> const* vec, std::vector<double>& values, bool reset) void DOFSerializer::gather(int macroIndex, DOFVector<double> const* vec, std::vector<double>& values, bool reset)
{ {
FUNCNAME("DOFSerializer::gather()");
TEST_EXIT(mesh_ == vec->getFeSpace()->getMesh())("Incompatible meshes!\n");
if (reset) { if (reset) {
std::fill(visited_.begin(), visited_.end(), false); std::fill(visited_.begin(), visited_.end(), false);
values.clear(); values.clear();
} }
TEST_EXIT(mesh_ == vec->getFeSpace()->getMesh())("Incompatible meshes!\n");
TraverseStack stack; TraverseStack stack;
ElInfo *elInfo = stack.traverseFirstOneMacro(mesh_, macroIndex, -1, Mesh::CALL_EVERY_EL_PREORDER); ElInfo *elInfo = stack.traverseFirstOneMacro(mesh_, macroIndex, -1, Mesh::CALL_EVERY_EL_PREORDER);
while (elInfo) { while (elInfo) {
Element *el = elInfo->getElement(); Element *el = elInfo->getElement();
if (el->isLeaf()) { if (el->isLeaf()) {
gather(VERTEX, elInfo, vec, values); gather(VERTEX, elInfo, vec, values);
if (mesh_->getDim() > 1) if (mesh_->getDim() > 1)
...@@ -43,14 +47,15 @@ void DOFSerializer::gather(int macroIndex, DOFVector<double> const* vec, std::ve ...@@ -43,14 +47,15 @@ void DOFSerializer::gather(int macroIndex, DOFVector<double> const* vec, std::ve
gather(FACE, elInfo, vec, values); gather(FACE, elInfo, vec, values);
gather(CENTER, elInfo, vec, values); gather(CENTER, elInfo, vec, values);
} }
elInfo = stack.traverseNext(elInfo); elInfo = stack.traverseNext(elInfo);
} }
} }
void DOFSerializer::gather(GeoIndex geo, ElInfo* elInfo, DOFVector<double> const* vec, std::vector<double>& values) void DOFSerializer::gather(GeoIndex geo, ElInfo* elInfo, DOFVector<double> const* vec, std::vector<double>& values)
{ {
FUNCNAME_DBG("DOFSerializer::gather()");
int nd; int nd;
if ((nd = admin_->getNumberOfDofs(geo))) { if ((nd = admin_->getNumberOfDofs(geo))) {
int entities = mesh_->getGeo(geo); int entities = mesh_->getGeo(geo);
...@@ -59,7 +64,7 @@ void DOFSerializer::gather(GeoIndex geo, ElInfo* elInfo, DOFVector<double> const ...@@ -59,7 +64,7 @@ void DOFSerializer::gather(GeoIndex geo, ElInfo* elInfo, DOFVector<double> const
for (int n = 0; n < entities; n++) { for (int n = 0; n < entities; n++) {
for(int d = 0; d < nd; d++) { for(int d = 0; d < nd; d++) {
DegreeOfFreedom globalDof = elInfo->getElement()->getDof(n0 + n, nd0 + d); DegreeOfFreedom globalDof = elInfo->getElement()->getDof(n0 + n, nd0 + d);
TEST_EXIT(globalDof < visited_.size())("visited container not large enough!\n"); TEST_EXIT_DBG(globalDof < visited_.size())("visited container not large enough!\n");
if (!visited_[globalDof]) { if (!visited_[globalDof]) {
visited_[globalDof] = true; visited_[globalDof] = true;
values.push_back((*vec)[globalDof]); values.push_back((*vec)[globalDof]);
...@@ -75,7 +80,7 @@ void DOFSerializer::scatter(std::vector<double> const& values, DOFVector<double> ...@@ -75,7 +80,7 @@ void DOFSerializer::scatter(std::vector<double> const& values, DOFVector<double>
{ {
std::fill(visited_.begin(), visited_.end(), false); std::fill(visited_.begin(), visited_.end(), false);
counter_ = 0u; counter_ = 0u;
for (auto* macroEl : mesh_->getMacroElements()) for (auto* macroEl : mesh_->getMacroElements())
scatter(macroEl->getIndex(), values, vec, false); scatter(macroEl->getIndex(), values, vec, false);
} }
...@@ -83,19 +88,20 @@ void DOFSerializer::scatter(std::vector<double> const& values, DOFVector<double> ...@@ -83,19 +88,20 @@ void DOFSerializer::scatter(std::vector<double> const& values, DOFVector<double>
// assign stored values to DOFVector, on macroElement with index `macroIndex` // assign stored values to DOFVector, on macroElement with index `macroIndex`
void DOFSerializer::scatter(int macroIndex, std::vector<double> const& values, DOFVector<double>* vec, bool reset) const void DOFSerializer::scatter(int macroIndex, std::vector<double> const& values, DOFVector<double>* vec, bool reset) const
{ {
FUNCNAME("DOFSerializer::scatter()");
TEST_EXIT(mesh_ == vec->getFeSpace()->getMesh())("Incompatible meshes!\n");
if (reset) { if (reset) {
std::fill(visited_.begin(), visited_.end(), false); std::fill(visited_.begin(), visited_.end(), false);
counter_ = 0u; counter_ = 0u;
} }
TEST_EXIT(mesh_ == vec->getFeSpace()->getMesh())("Incompatible meshes!\n");
TraverseStack stack; TraverseStack stack;
ElInfo *elInfo = stack.traverseFirstOneMacro(mesh_, macroIndex, -1, Mesh::CALL_EVERY_EL_PREORDER); ElInfo *elInfo = stack.traverseFirstOneMacro(mesh_, macroIndex, -1, Mesh::CALL_EVERY_EL_PREORDER);
while (elInfo) { while (elInfo) {
Element *el = elInfo->getElement(); Element *el = elInfo->getElement();
if (el->isLeaf()) { if (el->isLeaf()) {
scatter(VERTEX, elInfo, values, vec); scatter(VERTEX, elInfo, values, vec);
if (mesh_->getDim() > 1) if (mesh_->getDim() > 1)
...@@ -104,7 +110,7 @@ void DOFSerializer::scatter(int macroIndex, std::vector<double> const& values, D ...@@ -104,7 +110,7 @@ void DOFSerializer::scatter(int macroIndex, std::vector<double> const& values, D
scatter(FACE, elInfo, values, vec); scatter(FACE, elInfo, values, vec);
scatter(CENTER, elInfo, values, vec); scatter(CENTER, elInfo, values, vec);
} }
elInfo = stack.traverseNext(elInfo); elInfo = stack.traverseNext(elInfo);
} }
} }
...@@ -112,6 +118,7 @@ void DOFSerializer::scatter(int macroIndex, std::vector<double> const& values, D ...@@ -112,6 +118,7 @@ void DOFSerializer::scatter(int macroIndex, std::vector<double> const& values, D
void DOFSerializer::scatter(GeoIndex geo, ElInfo* elInfo, std::vector<double> const& values, DOFVector<double>* vec) const void DOFSerializer::scatter(GeoIndex geo, ElInfo* elInfo, std::vector<double> const& values, DOFVector<double>* vec) const
{ {
FUNCNAME("DOFSerializer::scatter()");
int nd; int nd;
if ((nd = admin_->getNumberOfDofs(geo))) { if ((nd = admin_->getNumberOfDofs(geo))) {
int entities = mesh_->getGeo(geo); int entities = mesh_->getGeo(geo);
...@@ -120,7 +127,7 @@ void DOFSerializer::scatter(GeoIndex geo, ElInfo* elInfo, std::vector<double> co ...@@ -120,7 +127,7 @@ void DOFSerializer::scatter(GeoIndex geo, ElInfo* elInfo, std::vector<double> co
for (int n = 0; n < entities; n++) { for (int n = 0; n < entities; n++) {
for(int d = 0; d < nd; d++) { for(int d = 0; d < nd; d++) {
DegreeOfFreedom globalDof = elInfo->getElement()->getDof(n0 + n, nd0 + d); DegreeOfFreedom globalDof = elInfo->getElement()->getDof(n0 + n, nd0 + d);
TEST_EXIT(globalDof < visited_.size())("visited container not large enough!\n"); TEST_EXIT_DBG(globalDof < visited_.size())("visited container not large enough!\n");
if (!visited_[globalDof]) { if (!visited_[globalDof]) {
visited_[globalDof] = true; visited_[globalDof] = true;
TEST_EXIT(counter_ < values.size())("Not enough values in value-container!\n"); TEST_EXIT(counter_ < values.size())("Not enough values in value-container!\n");
......
...@@ -41,47 +41,51 @@ namespace AMDiS ...@@ -41,47 +41,51 @@ namespace AMDiS
class DOFSerializer class DOFSerializer
{ {
public: public:
/// Constructor, stores a pointer to the DOFAdmin. If the number of values to store can be estimated, /// Constructor, stores a pointer to the DOFAdmin. If the number of values to store can be estimated,
/// pass a second argument `numValues` /// pass a second argument `numValues`
DOFSerializer(DOFAdmin* admin, std::size_t numValues = 0) DOFSerializer(DOFAdmin* admin, std::size_t numValues = 0u)
: admin_(admin) : admin_(admin)
, mesh_(admin->getMesh()) , mesh_(admin->getMesh())
, visited_(admin->getUsedSize(), false) , visited_(admin->getUsedSize(), false)
, numValues_(numValues)
{} {}
// satre values of DOFVector on all macro elements to internal container // store values of DOFVector on all macro elements to internal container
void gather(DOFVector<double> const* vec, std::vector<double>& values); void gather(DOFVector<double> const* vec, std::vector<double>& values);
// satre values of DOFVector on macro element `macroIndex` to internal container // store values of DOFVector on macro element `macroIndex` to internal container
void gather(int macroIndex, DOFVector<double> const* vec, std::vector<double>& values, bool reset = true); void gather(int macroIndex, DOFVector<double> const* vec, std::vector<double>& values, bool reset = true);
// assign stored values to DOFVector, for all macro elements // assign stored values to DOFVector, for all macro elements
void scatter(std::vector<double> const& values, DOFVector<double>* vec) const; void scatter(std::vector<double> const& values, DOFVector<double>* vec) const;
// assign stored values to DOFVector, on macroElement with index `macroIndex` // assign stored values to DOFVector, on macroElement with index `macroIndex`
void scatter(int macroIndex, std::vector<double> const& values, DOFVector<double>* vec, bool reset = true) const; void scatter(int macroIndex, std::vector<double> const& values, DOFVector<double>* vec, bool reset = true) const;
protected: protected:
// collect values of one geometry-type // collect values of one geometry-type
void gather(GeoIndex geo, ElInfo* elInfo, DOFVector<double> const* vec, std::vector<double>& values); void gather(GeoIndex geo, ElInfo* elInfo, DOFVector<double> const* vec, std::vector<double>& values);
// assign values of one geometry type // assign values of one geometry type
void scatter(GeoIndex geo, ElInfo* elInfo, std::vector<double> const& values, DOFVector<double>* vec) const; void scatter(GeoIndex geo, ElInfo* elInfo, std::vector<double> const& values, DOFVector<double>* vec) const;
protected: protected:
DOFAdmin* admin_; DOFAdmin* admin_;
Mesh* mesh_; Mesh* mesh_;
// stored which DOFs were already visited during traversal // stored which DOFs were already visited during traversal
mutable std::vector<bool> visited_; mutable std::vector<bool> visited_;
// estimated number of values
std::size_t numValues_ = 0u;
// a counter used during assignment of values. To guarantee the same order as during gather // a counter used during assignment of values. To guarantee the same order as during gather
mutable std::size_t counter_ = 0u; mutable std::size_t counter_ = 0u;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment