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

DOFSerializer cleaned up

parent 73bc0569
......@@ -9,27 +9,31 @@
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) {
......@@ -51,6 +55,7 @@ void DOFSerializer::gather(int macroIndex, DOFVector<double> const* vec, std::ve
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]);
......@@ -84,13 +89,14 @@ 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) {
......@@ -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");
......
......@@ -44,17 +44,18 @@ namespace AMDiS
/// 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);
......@@ -82,6 +83,9 @@ namespace AMDiS
// 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