Commit 28579d9b authored by Ned Coltman's avatar Ned Coltman Committed by Timo Koch
Browse files

[test][localview] Separate bind calls for efficient binding in element loops

parent 96f0f883
Pipeline #7305 passed with stages
......@@ -153,9 +153,10 @@ int main (int argc, char *argv[])
DUNE_THROW(Dune::InvalidStateException, "FvGridGeometry does not have exactly 52 scvfs!");
//! iterate over elements and check for each element the number of scvfs
auto fvGeometry = localView(gridGeometry);
for (const auto& element : elements(leafGridView))
{
const auto fvGeometry = localView(gridGeometry).bind(element);
fvGeometry.bind(element);
//! For the tpfa scheme there is always one scv per element
if (fvGeometry.numScv() != 1)
......
......@@ -41,9 +41,10 @@ void runTest(const GG& gg, const double refVolume, const double refSurface)
{
double volume = 0.0;
double surface = 0.0;
auto fvGeometry = localView(gg);
for (const auto& element : elements(gg.gridView()))
{
const auto fvGeometry = localView(gg).bind(element);
fvGeometry.bind(element);
for (const auto& scv : scvs(fvGeometry))
volume += GG::Extrusion::volume(scv);
......
......@@ -100,13 +100,14 @@ int main (int argc, char *argv[])
<< "norm in/out - dofIdx on face normal to own face (within own element / in adjacent element)" << std::endl;
// iterate over elements. For every element get fv geometry and loop over scvs and scvfaces
auto fvGeometry = localView(gridGeometry);
for (const auto& element : elements(leafGridView))
{
auto eIdx = gridGeometry.elementMapper().index(element);
if(eIdx == 12 || eIdx == 0)
{
std::cout << std::endl << "Checking fvGeometry of element " << eIdx << std::endl;
const auto fvGeometry = localView(gridGeometry).bind(element);
fvGeometry.bind(element);
auto range = scvs(fvGeometry);
Detail::NoopFunctor<SubControlVolume> op;
......
......@@ -71,9 +71,10 @@ auto createAnalyticalSolution(const Problem& problem)
analyticalVelocityOnFace.resize(gridGeometry.numFaceDofs());
using Indices = typename Problem::Indices;
auto fvGeometry = localView(gridGeometry);
for (const auto& element : elements(gridGeometry.gridView()))
{
const auto fvGeometry = localView(gridGeometry).bindElement(element);
fvGeometry.bindElement(element);
for (auto&& scv : scvs(fvGeometry))
{
auto ccDofIdx = scv.dofIndex();
......
......@@ -321,10 +321,10 @@ private:
analyticalPressure_.resize(this->gridGeometry().numCellCenterDofs());
analyticalVelocity_.resize(this->gridGeometry().numCellCenterDofs());
analyticalVelocityOnFace_.resize(this->gridGeometry().numFaceDofs());
auto fvGeometry = localView(this->gridGeometry());
for (const auto& element : elements(this->gridGeometry().gridView()))
{
const auto fvGeometry = localView(this->gridGeometry()).bindElement(element);
fvGeometry.bindElement(element);
for (auto&& scv : scvs(fvGeometry))
{
const auto ccDofIdx = scv.dofIndex();
......
......@@ -377,10 +377,10 @@ private:
analyticalPressure_.resize(this->gridGeometry().numCellCenterDofs());
analyticalVelocity_.resize(this->gridGeometry().numCellCenterDofs());
analyticalVelocityOnFace_.resize(this->gridGeometry().numFaceDofs());
auto fvGeometry = localView(this->gridGeometry());
for (const auto& element : elements(this->gridGeometry().gridView()))
{
const auto fvGeometry = localView(this->gridGeometry()).bindElement(element);
fvGeometry.bindElement(element);
for (auto&& scv : scvs(fvGeometry))
{
auto ccDofIdx = scv.dofIndex();
......
......@@ -292,9 +292,10 @@ private:
analyticalVelocity_.resize(this->gridGeometry().numCellCenterDofs());
analyticalVelocityOnFace_.resize(this->gridGeometry().numFaceDofs());
auto fvGeometry = localView(this->gridGeometry());
for (const auto& element : elements(this->gridGeometry().gridView()))
{
const auto fvGeometry = localView(this->gridGeometry()).bindElement(element);
fvGeometry.bindElement(element);
for (auto&& scv : scvs(fvGeometry))
{
const auto ccDofIdx = scv.dofIndex();
......
......@@ -251,9 +251,10 @@ private:
analyticalVelocity_.resize(this->gridGeometry().numCellCenterDofs());
analyticalVelocityOnFace_.resize(this->gridGeometry().numFaceDofs());
auto fvGeometry = localView(this->gridGeometry());
for (const auto& element : elements(this->gridGeometry().gridView()))
{
const auto fvGeometry = localView(this->gridGeometry()).bindElement(element);
fvGeometry.bindElement(element);
for (auto&& scv : scvs(fvGeometry))
{
const auto ccDofIdx = scv.dofIndex();
......
......@@ -63,10 +63,10 @@ public:
Scalar totalVolume = 0.0;
auto fvGeometry = localView(problem.gridGeometry());
for (const auto& element : elements(problem.gridGeometry().gridView()))
{
const auto fvGeometry = localView(problem.gridGeometry()).bindElement(element);
fvGeometry.bindElement(element);
for (auto&& scv : scvs(fvGeometry))
{
// treat cell-center dofs
......
......@@ -74,9 +74,10 @@ auto createAnalyticalSolution(const Scalar time, const Problem& problem)
analyticalVelocityOnFace.resize(gridGeometry.numFaceDofs());
using Indices = typename Problem::Indices;
auto fvGeometry = localView(gridGeometry);
for (const auto& element : elements(gridGeometry.gridView()))
{
const auto fvGeometry = localView(gridGeometry).bindElement(element);
fvGeometry.bindElement(element);
for (auto&& scv : scvs(fvGeometry))
{
const auto ccDofIdx = scv.dofIndex();
......@@ -117,9 +118,10 @@ auto createSource(const Problem& problem)
component.resize(gridGeometry.numCellCenterDofs());
}
auto fvGeometry = localView(gridGeometry);
for (const auto& element : elements(gridGeometry.gridView()))
{
const auto fvGeometry = localView(gridGeometry).bindElement(element);
fvGeometry.bindElement(element);
for (auto&& scv : scvs(fvGeometry))
{
const auto ccDofIdx = scv.dofIndex();
......
......@@ -209,15 +209,15 @@ public:
template<class GridVariables, class SolutionVector>
void calculateDeltaP(const GridVariables& gridVariables, const SolutionVector& sol)
{
auto fvGeometry = localView(this->gridGeometry());
auto elemVolVars = localView(gridVariables.curGridVolVars());
for (const auto& element : elements(this->gridGeometry().gridView()))
{
const auto fvGeometry = localView(this->gridGeometry()).bindElement(element);
fvGeometry.bindElement(element);
elemVolVars.bindElement(element, fvGeometry, sol);
for (auto&& scv : scvs(fvGeometry))
{
const auto ccDofIdx = scv.dofIndex();
const auto elemVolVars = localView(gridVariables.curGridVolVars()).bindElement(element, fvGeometry, sol);
deltaP_[ccDofIdx] = elemVolVars[scv].pressure() - 1.1e5;
}
}
......
......@@ -191,14 +191,15 @@ public:
template<class GridVariables, class SolutionVector>
void calculateDeltaRho(const GridVariables& gridVariables, const SolutionVector& sol)
{
auto fvGeometry = localView(this->gridGeometry());
auto elemVolVars = localView(gridVariables.curGridVolVars());
for (const auto& element : elements(this->gridGeometry().gridView()))
{
const auto fvGeometry = localView(this->gridGeometry()).bindElement(element);
fvGeometry.bindElement(element);
elemVolVars.bind(element, fvGeometry, sol);
for (auto&& scv : scvs(fvGeometry))
{
const auto ccDofIdx = scv.dofIndex();
const auto elemVolVars = localView(gridVariables.curGridVolVars()).bind(element, fvGeometry, sol);
deltaRho_[ccDofIdx] = elemVolVars[scv].density() - 999.694;
}
}
......
......@@ -96,10 +96,12 @@ public:
Scalar x_h2_right = 0.0;
Scalar i = 0.0;
Scalar j = 0.0;
auto fvGeometry = localView(this->gridGeometry());
auto elemVolVars = localView(gridVariables.curGridVolVars());
for (const auto& element : elements(this->gridGeometry().gridView()))
{
const auto fvGeometry = localView(this->gridGeometry()).bindElement(element);
const auto elemVolVars = localView(gridVariables.curGridVolVars()).bind(element, fvGeometry, curSol);
fvGeometry.bindElement(element);
elemVolVars.bind(element, fvGeometry, curSol);
for (auto&& scv : scvs(fvGeometry))
{
const auto globalPos = scv.dofPosition();
......
......@@ -78,9 +78,10 @@ computeL2Error(const double t,
const GridGeometry& gridGeometry)
{
typename SolutionVector::block_type l2Error(0.0);
auto fvGeometry = localView(gridGeometry);
for (const auto& element : elements(gridGeometry.gridView(), Dune::Partitions::interior))
{
const auto fvGeometry = localView(gridGeometry).bindElement(element);
fvGeometry.bindElement(element);
using std::pow;
for (auto&& scv : scvs(fvGeometry))
......
......@@ -106,10 +106,12 @@ public:
const Scalar time)
{
//compute solution for all elements
auto fvGeometry = localView(this->gridGeometry());
auto elemVolVars = localView(gridVariables.curGridVolVars());
for (const auto& element : elements(this->gridGeometry().gridView()))
{
const auto fvGeometry = localView(this->gridGeometry()).bindElement(element);
const auto elemVolVars = localView(gridVariables.curGridVolVars()).bindElement(element, fvGeometry, curSol);
fvGeometry.bindElement(element);
elemVolVars.bindElement(element, fvGeometry, curSol);
const auto& globalPos = element.geometry().center();
......
......@@ -62,10 +62,12 @@ void assembleElementStresses(SigmaStorage& sigmaStorage,
const GridVariables& gridVariables,
const SolutionVector& x)
{
auto fvGeometry = localView(gridGeometry);
auto elemVolVars = localView(gridVariables.curGridVolVars());
for (const auto& element : elements(gridGeometry.gridView()))
{
const auto fvGeometry = localView(gridGeometry).bind(element);
const auto elemVolVars = localView(gridVariables.curGridVolVars()).bind(element, fvGeometry, x);
fvGeometry.bind(element);
elemVolVars.bind(element, fvGeometry, x);
// evaluate flux variables cache at cell center
using FluxVarsCache = typename GridVariables::GridFluxVariablesCache::FluxVariablesCache;
......
......@@ -48,11 +48,10 @@ public:
std::shared_ptr<const GridGeometry> gridGeometry,
std::shared_ptr<const GridData<Grid>> gridData)
{
auto fvGeometry = localView(*gridGeometry);
for(const auto& element : elements(leafGridView))
{
const auto fvGeometry = localView(*gridGeometry).bind(element);
fvGeometry.bind(element);
for (auto&& scvf : scvfs(fvGeometry))
{
if (scvf.boundary())
......
......@@ -106,10 +106,12 @@ public:
Scalar massWater = 0.0;
// bulk elements
auto fvGeometry = localView(this->gridGeometry());
auto elemVolVars = localView(gridVariables.curGridVolVars());
for (const auto& element : elements(this->gridGeometry().gridView()))
{
const auto fvGeometry = localView(this->gridGeometry()).bindElement(element);
const auto elemVolVars = localView(gridVariables.curGridVolVars()).bindElement(element, fvGeometry, curSol);
fvGeometry.bindElement(element);
elemVolVars.bindElement(element, fvGeometry, curSol);
for (auto&& scv : scvs(fvGeometry))
{
......
......@@ -72,9 +72,10 @@ auto createFreeFlowAnalyticalSolution(const Problem& problem)
analyticalVelocityOnFace.resize(gridGeometry.numFaceDofs());
using Indices = typename Problem::Indices;
auto fvGeometry = localView(gridGeometry);
for (const auto& element : elements(gridGeometry.gridView()))
{
const auto fvGeometry = localView(gridGeometry).bindElement(element);
fvGeometry.bindElement(element);
for (auto&& scv : scvs(fvGeometry))
{
auto ccDofIdx = scv.dofIndex();
......@@ -122,10 +123,10 @@ auto createDarcyAnalyticalSolution(const Problem& problem)
analyticalPressure.resize(gridGeometry.numDofs());
analyticalVelocity.resize(gridGeometry.numDofs());
auto fvGeometry = localView(gridGeometry);
for (const auto& element : elements(gridGeometry.gridView()))
{
const auto fvGeometry = localView(gridGeometry).bindElement(element);
fvGeometry.bindElement(element);
for (auto&& scv : scvs(fvGeometry))
{
const auto ccDofIdx = scv.dofIndex();
......@@ -178,10 +179,10 @@ void printDarcyL2Error(const Problem& problem, const SolutionVector& x)
using Scalar = double;
Scalar l2error = 0.0;
auto fvGeometry = localView(problem.gridGeometry());
for (const auto& element : elements(problem.gridGeometry().gridView()))
{
const auto fvGeometry = localView(problem.gridGeometry()).bindElement(element);
fvGeometry.bindElement(element);
for (auto&& scv : scvs(fvGeometry))
{
......
......@@ -57,10 +57,12 @@ double computeSourceIntegral(const Problem& problem, const SolutionVector& sol,
{
const auto& gg = problem.gridGeometry();
typename SolutionVector::block_type source(0.0);
auto fvGeometry = localView(gg);
auto elemVolVars = localView(gridVars.curGridVolVars());
for (const auto& element : elements(gg.gridView()))
{
const auto fvGeometry = localView(gg).bindElement(element);
const auto elemVolVars = localView(gridVars.curGridVolVars()).bindElement(element, fvGeometry, sol);
fvGeometry.bindElement(element);
elemVolVars.bindElement(element, fvGeometry, sol);
for (auto&& scv : scvs(fvGeometry))
{
......
Supports Markdown
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