version 3.11-dev
Loading...
Searching...
No Matches
periodicconstraints.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
16#ifndef DUMUX_ASSEMBLY_PERIODIC_CONSTRAINTS_HH
17#define DUMUX_ASSEMBLY_PERIODIC_CONSTRAINTS_HH
18
19#include <algorithm>
20#include <cassert>
21
24
26
28template<class GridGeometry, class Function>
29void forEachPeriodicPair(const GridGeometry& gridGeometry, Function&& f)
30{
32 {
33 for (const auto& m : gridGeometry.periodicDofMap())
34 {
35 const auto& periodicallyMappedDofs = Dumux::Deprecated::ensureRangeOfPeriodicDofs(m.second);
36 if (std::ranges::all_of(periodicallyMappedDofs, [&](auto second){ return m.first < second; }))
37 for (const auto& second : periodicallyMappedDofs)
38 f(m.first, second);
39 }
40 }
41}
42
44template<class GridGeometry, class Residual, class Solution>
45void enforceInResidual(const GridGeometry& gridGeometry, Residual& res, const Solution& curSol)
46{
47 forEachPeriodicPair(gridGeometry, [&](const auto first, const auto second)
48 {
49 res[first] += res[second];
50 res[second] = curSol[second] - curSol[first];
51 });
52}
53
55template<class GridGeometry, class Matrix>
56void enforceInJacobian(const GridGeometry& gridGeometry, Matrix& jac)
57{
58 forEachPeriodicPair(gridGeometry, [&](const auto first, const auto second)
59 {
60 const auto end = jac[second].end();
61 for (auto it = jac[second].begin(); it != end; ++it)
62 jac[first][it.index()] += (*it);
63
64 for (auto it = jac[second].begin(); it != end; ++it)
65 {
66 auto& matrixBlock = *it;
67 matrixBlock = 0.0;
68
69 assert(matrixBlock.N() == matrixBlock.M());
70 const double diagValue = it.index() == second ? 1.0 : (it.index() == first ? -1.0 : 0.0);
71 if (diagValue != 0.0)
72 for (int eIdx = 0; eIdx < matrixBlock.N(); ++eIdx)
73 matrixBlock[eIdx][eIdx] = diagValue;
74 }
75 });
76}
77
78} // end namespace Dumux::Detail::PeriodicConstraints
79
80#endif
Helpers for deprecation.
Definition periodicconstraints.hh:25
void enforceInResidual(const GridGeometry &gridGeometry, Residual &res, const Solution &curSol)
Add the residual of each periodic degree of freedom to the one it is mapped to and replace it by the ...
Definition periodicconstraints.hh:45
void forEachPeriodicPair(const GridGeometry &gridGeometry, Function &&f)
Call f(first, second) for each periodically mapped degree of freedom second of the degree of freedom ...
Definition periodicconstraints.hh:29
void enforceInJacobian(const GridGeometry &gridGeometry, Matrix &jac)
Add the matrix row of each periodic degree of freedom to the one it is mapped to and replace it by th...
Definition periodicconstraints.hh:56
constexpr bool hasPeriodicDofMap()
Definition periodic.hh:24
Type traits to detect periodicity support.