version 3.11-dev
solidmechanics/plate/kirchhoff_love/couplingmanager.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_KIRCHHOFF_LOVE_PLATE_COUPLINGMANAGER_HH
13#define DUMUX_KIRCHHOFF_LOVE_PLATE_COUPLINGMANAGER_HH
14
15#include <memory>
16#include <tuple>
17#include <vector>
18#include <array>
19#include <type_traits>
20
21#include <dune/common/indices.hh>
22#include <dune/common/exceptions.hh>
23
27
30
32
33namespace Dumux {
34
35template<class MDTraits>
37: public CouplingManager<MDTraits>
38{
40 using Scalar = typename MDTraits::Scalar;
41 using SolutionVector = typename MDTraits::SolutionVector;
42
43 // the sub domain type tags
44 template<std::size_t id> using SubDomainTypeTag = typename MDTraits::template SubDomain<id>::TypeTag;
45 template<std::size_t id> using Problem = GetPropType<SubDomainTypeTag<id>, Properties::Problem>;
46 template<std::size_t id> using GridGeometry = GetPropType<SubDomainTypeTag<id>, Properties::GridGeometry>;
47 template<std::size_t id> using GridView = typename GridGeometry<id>::GridView;
48 template<std::size_t id> using Element = typename GridView<id>::template Codim<0>::Entity;
49 template<std::size_t id> using ElementSeed = typename GridView<id>::Grid::template Codim<0>::EntitySeed;
50 template<std::size_t id> using GridIndex = typename IndexTraits<GridView<id>>::GridIndex;
51 template<std::size_t id> using Indices
52 = typename GetPropType<SubDomainTypeTag<id>, Properties::GridVariables>::VolumeVariables::Indices;
53
54 template<std::size_t id> using CouplingStencil = std::vector<GridIndex<id>>;
55
56 using GlobalPosition = typename Element<0>::Geometry::GlobalCoordinate;
57
58
59
60public:
61 static constexpr auto rotationIdx = typename MDTraits::template SubDomain<0>::Index();
62 static constexpr auto deformationIdx = typename MDTraits::template SubDomain<1>::Index();
63
65 using MultiDomainTraits = MDTraits;
66
68
69 KirchhoffLovePlateCouplingManager(std::shared_ptr<GridGeometry<rotationIdx>> rotationsGG,
70 std::shared_ptr<GridGeometry<deformationIdx>> deformationGG)
71 {
72 const auto& rotationsGridGeometry = *rotationsGG;
73 const auto& deformationGridGeometry = *deformationGG;
74 auto rotGeo = localView(rotationsGridGeometry);
75 auto defGeo = localView(deformationGridGeometry);
76
77 defToRotStencils_.clear();
78 defToRotStencils_.resize(deformationGridGeometry.gridView().size(0));
79
80 rotToDefStencils_.clear();
81 rotToDefStencils_.resize(rotationsGridGeometry.gridView().size(0));
82
83 assert(defToRotStencils_.size() == rotToDefStencils_.size());
84
85 for (const auto& element : elements(rotationsGridGeometry.gridView()))
86 {
87 rotGeo.bindElement(element);
88 defGeo.bindElement(element);
89 const auto eIdx = rotGeo.elementIndex();
90
91 for (const auto& localDof : localDofs(rotGeo))
92 defToRotStencils_[eIdx].push_back(localDof.dofIndex());
93
94 for (const auto& localDof : localDofs(defGeo))
95 rotToDefStencils_[eIdx].push_back(localDof.dofIndex());
96 }
97 }
98
99 void init(std::shared_ptr<Problem<rotationIdx>> momentumProblem,
100 std::shared_ptr<Problem<deformationIdx>> massProblem,
101 const SolutionVector& curSol)
102 {
103 this->updateSolution(curSol);
104 this->setSubProblems(std::make_tuple(momentumProblem, massProblem));
105 }
106
107 template<std::size_t i, std::size_t j>
108 const CouplingStencil<j>& couplingStencil(Dune::index_constant<i> domainI,
109 const Element<i>& element,
110 Dune::index_constant<j> domainJ) const
111 {
112 static_assert(i != j, "A domain cannot be coupled to itself!");
113
114 const auto eIdx = this->problem(domainI).gridGeometry().elementMapper().index(element);
115 if constexpr (domainI == rotationIdx)
116 return rotToDefStencils_[eIdx];
117 else
118 return defToRotStencils_[eIdx];
119 }
120
121 auto rotation(typename GridGeometry<deformationIdx>::LocalView const& fvGeometry,
122 typename GridGeometry<deformationIdx>::SubControlVolumeFace const& scvf) const
123 {
124 const auto& gg = this->problem(rotationIdx).gridGeometry();
125 const auto elemSol = elementSolution(fvGeometry.element(), curSol(rotationIdx), gg);
126 return evalSolution(
127 fvGeometry.element(),
128 fvGeometry.element().geometry(),
129 gg, elemSol,
130 scvf.ipGlobal()
131 );
132 }
133
134 auto deformationAndPotentials(typename GridGeometry<rotationIdx>::LocalView const& fvGeometry,
135 typename GridGeometry<rotationIdx>::SubControlVolumeFace const& scvf) const
136 {
137 const auto& gg = this->problem(deformationIdx).gridGeometry();
138 const auto elemSol = elementSolution(fvGeometry.element(), curSol(deformationIdx), gg);
139 return evalSolution(
140 fvGeometry.element(),
141 fvGeometry.element().geometry(),
142 gg, elemSol,
143 scvf.ipGlobal()
144 );
145 }
146
148 { return Indices<deformationIdx>::shearCurlPotentialIdx; }
149
151 { return Indices<deformationIdx>::shearGradPotentialIdx; }
152
158 template<std::size_t i>
159 auto& curSol(Dune::index_constant<i> domainIdx)
160 { return ParentType::curSol(domainIdx); }
161
167 template<std::size_t i>
168 const auto& curSol(Dune::index_constant<i> domainIdx) const
169 { return ParentType::curSol(domainIdx); }
170
175 { elementSets_ = computeColoring(this->problem(deformationIdx).gridGeometry()).sets; }
176
183 template<std::size_t i, class AssembleElementFunc>
184 void assembleMultithreaded(Dune::index_constant<i> domainId, AssembleElementFunc&& assembleElement) const
185 {
186 if (elementSets_.empty())
187 DUNE_THROW(Dune::InvalidStateException,
188 "Call computeColorsForAssembly before assembling in parallel!");
189
190 // make this element loop run in parallel
191 // for this we have to color the elements so that we don't get
192 // race conditions when writing into the global matrix or modifying grid variable caches
193 // each color can be assembled using multiple threads
194 const auto& grid = this->problem(domainId).gridGeometry().gridView().grid();
195 for (const auto& elements : elementSets_)
196 {
197 Dumux::parallelFor(elements.size(), [&](const std::size_t n)
198 {
199 const auto element = grid.entity(elements[n]);
200 assembleElement(element);
201 });
202 }
203 }
204
205protected:
206 using ParentType::curSol;
207
208private:
210 std::deque<std::vector<ElementSeed<deformationIdx>>> elementSets_;
211
212 std::vector<CouplingStencil<deformationIdx>> rotToDefStencils_;
213 std::vector<CouplingStencil<rotationIdx>> defToRotStencils_;
214};
215
216// we support multithreaded assembly
217template<class MDTraits>
219: public std::true_type {};
220
221} // end namespace Dumux
222
223#endif
The interface of the coupling manager for multi domain problems.
Definition: multidomain/couplingmanager.hh:37
void setSubProblems(const std::tuple< std::shared_ptr< SubProblems >... > &problems)
set the pointers to the sub problems
Definition: multidomain/couplingmanager.hh:297
const Problem< i > & problem(Dune::index_constant< i > domainIdx) const
Return a reference to the sub problem.
Definition: multidomain/couplingmanager.hh:319
SubSolutionVector< i > & curSol(Dune::index_constant< i > domainIdx)
the solution vector of the subproblem
Definition: multidomain/couplingmanager.hh:348
void updateSolution(const SolutionVector &curSol)
Updates the entire solution vector, e.g. before assembly or after grid adaption Overload might want t...
Definition: multidomain/couplingmanager.hh:229
Definition: solidmechanics/plate/kirchhoff_love/couplingmanager.hh:38
void assembleMultithreaded(Dune::index_constant< i > domainId, AssembleElementFunc &&assembleElement) const
Execute assembly kernel in parallel.
Definition: solidmechanics/plate/kirchhoff_love/couplingmanager.hh:184
MDTraits MultiDomainTraits
export traits
Definition: solidmechanics/plate/kirchhoff_love/couplingmanager.hh:65
auto & curSol(Dune::index_constant< i > domainIdx)
the solution vector of the subproblem
Definition: solidmechanics/plate/kirchhoff_love/couplingmanager.hh:159
const auto & curSol(Dune::index_constant< i > domainIdx) const
the solution vector of the subproblem
Definition: solidmechanics/plate/kirchhoff_love/couplingmanager.hh:168
void computeColorsForAssembly()
Compute colors for multithreaded assembly.
Definition: solidmechanics/plate/kirchhoff_love/couplingmanager.hh:174
static constexpr auto deformationIdx
Definition: solidmechanics/plate/kirchhoff_love/couplingmanager.hh:62
auto rotation(typename GridGeometry< deformationIdx >::LocalView const &fvGeometry, typename GridGeometry< deformationIdx >::SubControlVolumeFace const &scvf) const
Definition: solidmechanics/plate/kirchhoff_love/couplingmanager.hh:121
auto shearCurlPotentialIdx() const
Definition: solidmechanics/plate/kirchhoff_love/couplingmanager.hh:147
const CouplingStencil< j > & couplingStencil(Dune::index_constant< i > domainI, const Element< i > &element, Dune::index_constant< j > domainJ) const
Definition: solidmechanics/plate/kirchhoff_love/couplingmanager.hh:108
void init(std::shared_ptr< Problem< rotationIdx > > momentumProblem, std::shared_ptr< Problem< deformationIdx > > massProblem, const SolutionVector &curSol)
Definition: solidmechanics/plate/kirchhoff_love/couplingmanager.hh:99
auto deformationAndPotentials(typename GridGeometry< rotationIdx >::LocalView const &fvGeometry, typename GridGeometry< rotationIdx >::SubControlVolumeFace const &scvf) const
Definition: solidmechanics/plate/kirchhoff_love/couplingmanager.hh:134
static constexpr auto rotationIdx
Definition: solidmechanics/plate/kirchhoff_love/couplingmanager.hh:61
KirchhoffLovePlateCouplingManager(std::shared_ptr< GridGeometry< rotationIdx > > rotationsGG, std::shared_ptr< GridGeometry< deformationIdx > > deformationGG)
Definition: solidmechanics/plate/kirchhoff_love/couplingmanager.hh:69
auto shearGradPotentialIdx() const
Definition: solidmechanics/plate/kirchhoff_love/couplingmanager.hh:150
Coloring schemes for shared-memory-parallel assembly.
Defines all properties used in Dumux.
Element solution classes and factory functions.
free functions for the evaluation of primary variables inside elements.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
PrimaryVariables evalSolution(const Element &element, const typename Element::Geometry &geometry, const typename FVElementGeometry::GridGeometry &gridGeometry, const CVFEElementSolution< FVElementGeometry, PrimaryVariables > &elemSol, const typename Element::Geometry::GlobalCoordinate &globalPos, bool ignoreState=false)
Interpolates a given box element solution at a given global position. Uses the finite element cache o...
Definition: evalsolution.hh:198
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethods::cctpfa||GridGeometry::discMethod==DiscretizationMethods::ccmpfa, CCElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for cell-centered schemes.
Definition: cellcentered/elementsolution.hh:101
void parallelFor(const std::size_t count, const FunctorType &functor)
A parallel for loop (multithreading)
Definition: parallel_for.hh:160
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
The interface of the coupling manager for multi domain problems.
Definition: adapt.hh:17
auto computeColoring(const GridGeometry &gg, int verbosity=1)
Compute iterable lists of element seeds partitioned by color.
Definition: coloring.hh:241
auto localDofs(const FVElementGeometry &fvGeometry)
range over local dofs
Definition: localdof.hh:50
Parallel for loop (multithreading)
Type trait that is specialized for coupling manager supporting multithreaded assembly.
Definition: multistagemultidomainfvassembler.hh:78
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:26