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

DOFSerializer cleaned up

parent 73bc0569
......@@ -7,34 +7,38 @@
#include "Traverse.h"
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)
{
std::fill(visited_.begin(), visited_.end(), false);
values.clear();
values.reserve(numValues_);
for (auto* macroEl : mesh_->getMacroElements())
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)
{
FUNCNAME("DOFSerializer::gather()");
TEST_EXIT(mesh_ == vec->getFeSpace()->getMesh())("Incompatible meshes!\n");
if (reset) {
std::fill(visited_.begin(), visited_.end(), false);
values.clear();
}
TEST_EXIT(mesh_ == vec->getFeSpace()->getMesh())("Incompatible meshes!\n");
TraverseStack stack;
ElInfo *elInfo = stack.traverseFirstOneMacro(mesh_, macroIndex, -1, Mesh::CALL_EVERY_EL_PREORDER);
while (elInfo) {
Element *el = elInfo->getElement();
if (el->isLeaf()) {
gather(VERTEX, elInfo, vec, values);
if (mesh_->getDim() > 1)
......@@ -43,14 +47,15 @@ void DOFSerializer::gather(int macroIndex, DOFVector<double> const* vec, std::ve
gather(FACE, elInfo, vec, values);
gather(CENTER, elInfo, vec, values);
}
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;
if ((nd = admin_->getNumberOfDofs(geo))) {
int entities = mesh_->getGeo(geo);
......@@ -59,7 +64,7 @@ void DOFSerializer::gather(GeoIndex geo, ElInfo* elInfo, DOFVector<double> const
for (int n = 0; n < entities; n++) {
for(int d = 0; d < nd; 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]) {
visited_[globalDof] = true;
values.push_back((*vec)[globalDof]);
......@@ -75,7 +80,7 @@ void DOFSerializer::scatter(std::vector<double> const& values, DOFVector<double>
{
std::fill(visited_.begin(), visited_.end(), false);
counter_ = 0u;
for (auto* macroEl : mesh_->getMacroElements())
scatter(macroEl->getIndex(), values, vec, false);
}
......@@ -83,19 +88,20 @@ void DOFSerializer::scatter(std::vector<double> const& values, DOFVector<double>
// 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
{
{
FUNCNAME("DOFSerializer::scatter()");
TEST_EXIT(mesh_ == vec->getFeSpace()->getMesh())("Incompatible meshes!\n");
if (reset) {
std::fill(visited_.begin(), visited_.end(), false);
counter_ = 0u;
}
TEST_EXIT(mesh_ == vec->getFeSpace()->getMesh())("Incompatible meshes!\n");
TraverseStack stack;
ElInfo *elInfo = stack.traverseFirstOneMacro(mesh_, macroIndex, -1, Mesh::CALL_EVERY_EL_PREORDER);
while (elInfo) {
Element *el = elInfo->getElement();
if (el->isLeaf()) {
scatter(VERTEX, elInfo, values, vec);
if (mesh_->getDim() > 1)
......@@ -104,7 +110,7 @@ void DOFSerializer::scatter(int macroIndex, std::vector<double> const& values, D
scatter(FACE, elInfo, values, vec);
scatter(CENTER, elInfo, values, vec);
}
elInfo = stack.traverseNext(elInfo);
}
}
......@@ -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
{
FUNCNAME("DOFSerializer::scatter()");
int nd;
if ((nd = admin_->getNumberOfDofs(geo))) {
int entities = mesh_->getGeo(geo);
......@@ -120,7 +127,7 @@ void DOFSerializer::scatter(GeoIndex geo, ElInfo* elInfo, std::vector<double> co
for (int n = 0; n < entities; n++) {
for(int d = 0; d < nd; 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]) {
visited_[globalDof] = true;
TEST_EXIT(counter_ < values.size())("Not enough values in value-container!\n");
......
......@@ -41,47 +41,51 @@ namespace AMDiS
class DOFSerializer
{
public:
/// Constructor, stores a pointer to the DOFAdmin. If the number of values to store can be estimated,
/// pass a second argument `numValues`
DOFSerializer(DOFAdmin* admin, std::size_t numValues = 0)
DOFSerializer(DOFAdmin* admin, std::size_t numValues = 0u)
: admin_(admin)
, mesh_(admin->getMesh())
, 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);
// 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);
// assign stored values to DOFVector, for all macro elements
void scatter(std::vector<double> const& values, DOFVector<double>* vec) const;
// 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;
protected:
// collect values of one geometry-type
void gather(GeoIndex geo, ElInfo* elInfo, DOFVector<double> const* vec, std::vector<double>& values);
// assign values of one geometry type
void scatter(GeoIndex geo, ElInfo* elInfo, std::vector<double> const& values, DOFVector<double>* vec) const;
protected:
DOFAdmin* admin_;
Mesh* mesh_;
// stored which DOFs were already visited during traversal
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
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