Commit b74728f3 authored by Felix Gruber's avatar Felix Gruber

add function to copy from global to local vector

This new function conveys our intend much better than manually copying
the entries using iterateOverLocalIndices.
parent a2e732d0
Pipeline #15515 passed with stage
in 25 minutes and 29 seconds
......@@ -33,17 +33,8 @@ inline static void interiorImpl(
BlockVector<FieldVector<double,1>>
localFunctionalVector(solutionLocalView.size());
iterateOverLocalIndices(
solutionLocalView,
[&](size_t j, auto gj) {
localFunctionalVector[j] = functionalVector[gj[0]];
},
[&](size_t j) { localFunctionalVector[j] = 0; },
[&](size_t j, auto gj, double wj) {
localFunctionalVector[j] += wj * functionalVector[gj[0]];
}
);
copyToLocalVector(functionalVector, localFunctionalVector,
solutionLocalView);
const auto referenceGridView =
testLocalView.tree().refinedReferenceElementGridView();
......@@ -130,19 +121,8 @@ faceImpl(TestLocalView& testLocalView,
BlockVector<FieldVector<double,1>>
localFunctionalVector(solutionLocalView.size());
iterateOverLocalIndices(
solutionLocalView,
[&](size_t j, auto gj) {
localFunctionalVector[j]
= functionalVector[gj[0]];
},
[&](size_t j) { localFunctionalVector[j] = 0; },
[&](size_t j, auto gj, double wj) {
localFunctionalVector[j]
+= wj * functionalVector[gj[0]];
}
);
copyToLocalVector(functionalVector, localFunctionalVector,
solutionLocalView);
const auto referenceGridView =
testLocalView.tree().refinedReferenceElementGridView();
......
......@@ -35,17 +35,8 @@ inline static void interiorImpl(
BlockVector<FieldVector<double,1>>
localFunctionalVector(solutionLocalView.size());
iterateOverLocalIndices(
solutionLocalView,
[&](size_t j, auto gj) {
localFunctionalVector[j] = functionalVector[gj[0]];
},
[&](size_t j) { localFunctionalVector[j] = 0; },
[&](size_t j, auto gj, double wj) {
localFunctionalVector[j] += wj * functionalVector[gj[0]];
}
);
copyToLocalVector(functionalVector, localFunctionalVector,
solutionLocalView);
const auto referenceGridView =
testLocalView.tree().refinedReferenceElementGridView();
......@@ -128,17 +119,8 @@ faceImpl(TestLocalView& testLocalView,
BlockVector<FieldVector<double,1>>
localFunctionalVector(solutionLocalView.size());
iterateOverLocalIndices(
solutionLocalView,
[&](size_t j, auto gj) {
localFunctionalVector[j] = functionalVector[gj[0]];
},
[&](size_t j) { localFunctionalVector[j] = 0; },
[&](size_t j, auto gj, double wj) {
localFunctionalVector[j] += wj * functionalVector[gj[0]];
}
);
copyToLocalVector(functionalVector, localFunctionalVector,
solutionLocalView);
const auto referenceGridView =
testLocalView.tree().refinedReferenceElementGridView();
......
......@@ -36,17 +36,8 @@ inline static void interiorImpl(
BlockVector<FieldVector<double,1>>
localFunctionalVector(solutionLocalView.size());
iterateOverLocalIndices(
solutionLocalView,
[&](size_t j, auto gj) {
localFunctionalVector[j] = functionalVector[gj[0]];
},
[&](size_t j) { localFunctionalVector[j] = 0; },
[&](size_t j, auto gj, double wj) {
localFunctionalVector[j] += wj * functionalVector[gj[0]];
}
);
copyToLocalVector(functionalVector, localFunctionalVector,
solutionLocalView);
const unsigned int quadratureOrder
= solutionLocalFiniteElement.localBasis().order()
......@@ -122,17 +113,8 @@ faceImpl(const TestLocalView& testLocalView,
BlockVector<FieldVector<double,1>>
localFunctionalVector(solutionLocalView.size());
iterateOverLocalIndices(
solutionLocalView,
[&](size_t j, auto gj) {
localFunctionalVector[j] = functionalVector[gj[0]];
},
[&](size_t j) { localFunctionalVector[j] = 0; },
[&](size_t j, auto gj, double wj) {
localFunctionalVector[j] += wj * functionalVector[gj[0]];
}
);
copyToLocalVector(functionalVector, localFunctionalVector,
solutionLocalView);
for (unsigned short f = 0, fMax = element.subEntities(1); f < fMax; f++)
{
......
......@@ -87,20 +87,7 @@ public:
void bind(const Element& element)
{
localBasisView_.bind(element);
localDoFs_.resize(localBasisView_.size());
iterateOverLocalIndices(
localBasisView_,
[&](size_type i, auto gi) {
localDoFs_[i] = globalFunction_.dofs()[gi];
},
[&](size_type i) {
localDoFs_[i] = 0;
},
[&](size_type i, auto gi, double wi) {
localDoFs_[i] += wi * globalFunction_.dofs()[gi];
}
);
copyToLocalVector(globalFunction_.dofs(), localDoFs_, localBasisView_);
}
void unbind()
......
......@@ -59,17 +59,7 @@ namespace Dune
getLocalDataVector(const LocalView& localView, const VectorType& data)
{
VectorType localVector(localView.size());
iterateOverLocalIndices(
localView,
[&](size_t j, auto gj) {
localVector[j] = data[gj[0]];
},
[&](size_t j) { localVector[j] = 0; },
[&](size_t j, auto gj, double wj) {
localVector[j] += wj * data[gj[0]];
}
);
copyToLocalVector(data, localVector, localView);
return localVector;
}
......@@ -94,7 +84,8 @@ namespace Dune
using ctype = typename GridView::Grid::ctype;
constexpr static int dim = GridView::dimension;
const GridView gridView = feBasis.gridView();
std::vector<FieldVector<double,1> > feValues;
std::vector<FieldVector<double,1>> feValues;
feValues.reserve(localView.maxSize());
for(const auto& e : elements(gridView)) {
localView.bind(e);
const VectorType localData = getLocalDataVector(localView, data);
......
......@@ -81,6 +81,26 @@ void iterateOverLocalIndices(
std::forward<ConstrainedEvaluation>(constrainedEvaluation));
}
template<class LocalView,
class GlobalVector,
class LocalVector>
void copyToLocalVector(const GlobalVector& globalVector,
LocalVector& localVector,
LocalView&& localView) {
localVector.resize(localView.size());
iterateOverLocalIndices(
localView,
[&](size_t j, auto gj) {
localVector[j] = globalVector[gj[0]];
},
[&](size_t j) { localVector[j] = 0; },
[&](size_t j, auto gj, double wj) {
localVector[j] += wj * globalVector[gj[0]];
}
);
}
template<class TestLocalView,
class SolutionLocalView,
class GetLocalMatrixEntry,
......
......@@ -37,18 +37,7 @@ attachDataToGrid(
*(localEntitySeed++) = e.seed();
iterateOverLocalIndices(
localView,
[&](size_t i, auto gi)
{
localData[i] = data[gi[0]];
},
[&](size_t i){ localData[i] = 0; },
[&](size_t i, auto gi, double wi)
{
localData[i] += wi * data[gi[0]];
}
);
copyToLocalVector(data, localData, localView);
localData += maxEntityDoFs;
}
assert(localData == entityData.end());
......
......@@ -591,18 +591,7 @@ public:
std::vector<FieldVector<double, 1>>
hostGridLocalData(localView.size());
iterateOverLocalIndices(
localView,
[&](size_t i, auto gi)
{
hostGridLocalData[i] = hostGridData[gi[0]];
},
[&](size_t i){ hostGridLocalData[i] = 0; },
[&](size_t i, auto gi, double wi)
{
hostGridLocalData[i] += wi * hostGridData[gi[0]];
}
);
copyToLocalVector(hostGridData, hostGridLocalData, localView);
cellData.reserve(1);
// direct transfer of hostGridData
// Will be later interpolated in the call to
......@@ -618,18 +607,7 @@ public:
std::vector<FieldVector<double, 1>>
hostGridLocalData(localView.size());
iterateOverLocalIndices(
localView,
[&](size_t i, auto gi)
{
hostGridLocalData[i] = hostGridData[gi[0]];
},
[&](size_t i){ hostGridLocalData[i] = 0; },
[&](size_t i, auto gi, double wi)
{
hostGridLocalData[i] += wi * hostGridData[gi[0]];
}
);
copyToLocalVector(hostGridData, hostGridLocalData, localView);
cellData.emplace_back(child.seed(), std::move(hostGridLocalData));
}
}
......
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