version 3.11-dev
Loading...
Searching...
No Matches
couplingjacobianpattern.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//
12#ifndef DUMUX_MUTLIDOMAIN_COUPLING_JACOBIAN_PATTERN_HH
13#define DUMUX_MUTLIDOMAIN_COUPLING_JACOBIAN_PATTERN_HH
14
15#include <type_traits>
16#include <dune/common/indices.hh>
17#include <dune/istl/matrixindexset.hh>
20
22
23namespace Dumux {
24
30template<bool isImplicit, class CouplingManager, class GridGeometryI, class GridGeometryJ, std::size_t i, std::size_t j,
31 typename std::enable_if_t<( (GridGeometryI::discMethod == DiscretizationMethods::cctpfa)
32 || (GridGeometryI::discMethod == DiscretizationMethods::ccmpfa) ), int> = 0>
33Dune::MatrixIndexSet getCouplingJacobianPattern(const CouplingManager& couplingManager,
34 Dune::index_constant<i> domainI,
35 const GridGeometryI& gridGeometryI,
36 Dune::index_constant<j> domainJ,
37 const GridGeometryJ& gridGeometryJ)
38{
39 const auto numDofsI = gridGeometryI.numDofs();
40 const auto numDofsJ = gridGeometryJ.numDofs();
41 Dune::MatrixIndexSet pattern;
42 pattern.resize(numDofsI, numDofsJ);
43
44 // matrix pattern for implicit Jacobians
45 if (isImplicit)
46 {
47 for (const auto& elementI : elements(gridGeometryI.gridView()))
48 {
49 const auto& stencil = couplingManager.couplingStencil(domainI, elementI, domainJ);
50 const auto globalI = gridGeometryI.elementMapper().index(elementI);
51 for (const auto globalJ : stencil)
52 pattern.add(globalI, globalJ);
53 }
54 }
55
56 // matrix pattern for explicit Jacobians
57 // -> diagonal matrix, so coupling block is empty
58 // just return the empty pattern
59
60 return pattern;
61}
62
68template<bool isImplicit, class CouplingManager, class GridGeometryI, class GridGeometryJ, std::size_t i, std::size_t j,
69 typename std::enable_if_t<(GridGeometryI::discMethod == DiscretizationMethods::staggered &&
70 GridGeometryI::isCellCenter()), int> = 0>
71Dune::MatrixIndexSet getCouplingJacobianPattern(const CouplingManager& couplingManager,
72 Dune::index_constant<i> domainI,
73 const GridGeometryI& gridGeometryI,
74 Dune::index_constant<j> domainJ,
75 const GridGeometryJ& gridGeometryJ)
76{
77 Dune::MatrixIndexSet pattern(gridGeometryI.numDofs(), gridGeometryJ.numDofs());
78
79 for (const auto& elementI : elements(gridGeometryI.gridView()))
80 {
81 const auto ccGlobalI = gridGeometryI.elementMapper().index(elementI);
82 for (auto&& faceGlobalJ : couplingManager.couplingStencil(domainI, elementI, domainJ))
83 pattern.add(ccGlobalI, faceGlobalJ);
84 }
85
86 return pattern;
87}
88
94template<bool isImplicit, class CouplingManager, class GridGeometryI, class GridGeometryJ, std::size_t i, std::size_t j,
95 typename std::enable_if_t<(GridGeometryI::discMethod == DiscretizationMethods::staggered &&
96 GridGeometryI::isFace()), int> = 0>
97Dune::MatrixIndexSet getCouplingJacobianPattern(const CouplingManager& couplingManager,
98 Dune::index_constant<i> domainI,
99 const GridGeometryI& gridGeometryI,
100 Dune::index_constant<j> domainJ,
101 const GridGeometryJ& gridGeometryJ)
102{
103 Dune::MatrixIndexSet pattern(gridGeometryI.numDofs(), gridGeometryJ.numDofs());
104
105 auto fvGeometry = localView(gridGeometryI);
106 for (const auto& elementI : elements(gridGeometryI.gridView()))
107 {
108 fvGeometry.bindElement(elementI);
109
110 // loop over sub control faces
111 for (auto&& scvf : scvfs(fvGeometry))
112 {
113 const auto faceGlobalI = scvf.dofIndex();
114 for (auto&& globalJ : couplingManager.couplingStencil(domainI, scvf, domainJ))
115 pattern.add(faceGlobalI, globalJ);
116 }
117 }
118
119 return pattern;
120}
121
127template<bool isImplicit, class CouplingManager, class GridGeometryI, class GridGeometryJ, std::size_t i, std::size_t j,
128 typename std::enable_if_t<(GridGeometryI::discMethod == DiscretizationMethods::fcstaggered), int> = 0>
129Dune::MatrixIndexSet getCouplingJacobianPattern(const CouplingManager& couplingManager,
130 Dune::index_constant<i> domainI,
131 const GridGeometryI& gridGeometryI,
132 Dune::index_constant<j> domainJ,
133 const GridGeometryJ& gridGeometryJ)
134{
135 Dune::MatrixIndexSet pattern(gridGeometryI.numDofs(), gridGeometryJ.numDofs());
136
137 auto fvGeometry = localView(gridGeometryI);
138 for (const auto& elementI : elements(gridGeometryI.gridView()))
139 {
140 fvGeometry.bindElement(elementI);
141 for (const auto& scv : scvs(fvGeometry))
142 {
143 const auto globalI = scv.dofIndex();
144 const auto globalIP = gridGeometryI.isPeriodic() && gridGeometryI.dofOnPeriodicBoundary(globalI)
145 ? std::ranges::min(Dumux::Deprecated::rangeOfPeriodicallyMappedDofs(gridGeometryI,globalI))
146 : globalI;
147 const auto& stencil = couplingManager.couplingStencil(domainI, elementI, scv, domainJ);
148 for (const auto globalJ : stencil)
149 {
150 assert(globalJ < gridGeometryJ.numDofs());
151 pattern.add(globalI, globalJ);
152
153 if (globalI > globalIP)
154 pattern.add(globalIP, globalJ);
155 }
156 }
157 }
158
159 return pattern;
160}
161
167template<bool isImplicit, class CouplingManager, class GridGeometryI, class GridGeometryJ, std::size_t i, std::size_t j,
168 typename std::enable_if_t<DiscretizationMethods::isCVFE<typename GridGeometryI::DiscretizationMethod>, int> = 0>
169Dune::MatrixIndexSet getCouplingJacobianPattern(const CouplingManager& couplingManager,
170 Dune::index_constant<i> domainI,
171 const GridGeometryI& gridGeometryI,
172 Dune::index_constant<j> domainJ,
173 const GridGeometryJ& gridGeometryJ)
174{
175 Dune::MatrixIndexSet pattern;
176
177 // matrix pattern for implicit Jacobians
178 if constexpr (isImplicit)
179 {
180 pattern.resize(gridGeometryI.numDofs(), gridGeometryJ.numDofs());
181 auto fvGeometry = localView(gridGeometryI);
182 for (const auto& elementI : elements(gridGeometryI.gridView()))
183 {
184 fvGeometry.bindElement(elementI);
185 const auto& stencil = couplingManager.couplingStencil(domainI, elementI, domainJ);
186 for (const auto& localDof : localDofs(fvGeometry))
187 {
188 const auto globalI = localDof.dofIndex();
189 const auto globalIP = gridGeometryI.isPeriodic() && gridGeometryI.dofOnPeriodicBoundary(globalI)
190 ? std::ranges::min(Dumux::Deprecated::rangeOfPeriodicallyMappedDofs(gridGeometryI,globalI))
191 : globalI;
192 for (const auto globalJ : stencil)
193 {
194 pattern.add(globalI, globalJ);
195
196 if (globalI > globalIP)
197 pattern.add(globalIP, globalJ);
198 }
199
200 }
201 }
202 }
203
204 // matrix pattern for explicit Jacobians
205 // -> diagonal matrix, so coupling block is empty
206 // just return the empty pattern
207
208 return pattern;
209}
210
211} // end namespace Dumux
212
213#endif
The interface of the coupling manager for multi domain problems.
Definition multidomain/couplingmanager.hh:37
const CouplingStencilType< i, j > & couplingStencil(Dune::index_constant< i > domainI, const Element< i > &elementI, Dune::index_constant< j > domainJ) const
returns an iterable container of all indices of degrees of freedom of domain j that couple with / inf...
Definition multidomain/couplingmanager.hh:102
Helpers for deprecation.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition localview.hh:26
Dune::MatrixIndexSet getCouplingJacobianPattern(const CouplingManager &couplingManager, Dune::index_constant< i > domainI, const GridGeometryI &gridGeometryI, Dune::index_constant< j > domainJ, const GridGeometryJ &gridGeometryJ)
Helper function to generate coupling Jacobian pattern (off-diagonal blocks) for cell-centered schemes...
Definition couplingjacobianpattern.hh:33
Class representing dofs on elements for control-volume finite element schemes.
The available discretization methods in Dumux.
constexpr CCMpfa ccmpfa
Definition method.hh:175
constexpr CCTpfa cctpfa
Definition method.hh:174
constexpr Staggered staggered
Definition method.hh:181
constexpr FCStaggered fcstaggered
Definition method.hh:183
Definition adapt.hh:17
std::ranges::range auto scvs(const FVElementGeometry &fvGeometry, const LocalDof &localDof)
Definition localdof.hh:82
auto localDofs(const FVElementGeometry &fvGeometry)
range over local dofs
Definition localdof.hh:50