version 3.11-dev
Loading...
Searching...
No Matches
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
33
34namespace Dumux {
35
36template<class MDTraits>
38: public CouplingManager<MDTraits>
39{
40 using ParentType = CouplingManager<MDTraits>;
41 using Scalar = typename MDTraits::Scalar;
42 using SolutionVector = typename MDTraits::SolutionVector;
43
44 // the sub domain type tags
45 template<std::size_t id> using SubDomainTypeTag = typename MDTraits::template SubDomain<id>::TypeTag;
46 template<std::size_t id> using Problem = GetPropType<SubDomainTypeTag<id>, Properties::Problem>;
47 template<std::size_t id> using GridGeometry = GetPropType<SubDomainTypeTag<id>, Properties::GridGeometry>;
48 template<std::size_t id> using GridView = typename GridGeometry<id>::GridView;
49 template<std::size_t id> using Element = typename GridView<id>::template Codim<0>::Entity;
50 template<std::size_t id> using ElementSeed = typename GridView<id>::Grid::template Codim<0>::EntitySeed;
51 template<std::size_t id> using GridIndex = typename IndexTraits<GridView<id>>::GridIndex;
52 template<std::size_t id> using Indices
53 = typename GetPropType<SubDomainTypeTag<id>, Properties::GridVariables>::VolumeVariables::Indices;
54
55 template<std::size_t id> using CouplingStencil = std::vector<GridIndex<id>>;
56
57 using GlobalPosition = typename Element<0>::Geometry::GlobalCoordinate;
58
59
60
61public:
62 static constexpr auto rotationIdx = typename MDTraits::template SubDomain<0>::Index();
63 static constexpr auto deformationIdx = typename MDTraits::template SubDomain<1>::Index();
64
66 using MultiDomainTraits = MDTraits;
71 KirchhoffLovePlateCouplingManager(std::shared_ptr<GridGeometry<rotationIdx>> rotationsGG,
72 std::shared_ptr<GridGeometry<deformationIdx>> deformationGG)
73 { computeStencils(rotationsGG, deformationGG); }
74
80 */
81 void computeStencils(std::shared_ptr<GridGeometry<rotationIdx>> rotationsGG,
82 std::shared_ptr<GridGeometry<deformationIdx>> deformationGG)
83 {
84 const auto& rotationsGridGeometry = *rotationsGG;
85 const auto& deformationGridGeometry = *deformationGG;
86 auto rotGeo = localView(rotationsGridGeometry);
87 auto defGeo = localView(deformationGridGeometry);
88
89 defToRotStencils_.clear();
90 defToRotStencils_.resize(deformationGridGeometry.gridView().size(0));
91
92 rotToDefStencils_.clear();
93 rotToDefStencils_.resize(rotationsGridGeometry.gridView().size(0));
94
95 assert(defToRotStencils_.size() == rotToDefStencils_.size());
96
97 for (const auto& element : elements(rotationsGridGeometry.gridView()))
98 {
99 rotGeo.bindElement(element);
100 defGeo.bindElement(element);
101 const auto eIdx = rotGeo.elementIndex();
102
103 for (const auto& localDof : localDofs(rotGeo))
104 defToRotStencils_[eIdx].push_back(localDof.dofIndex());
105
106 for (const auto& localDof : localDofs(defGeo))
107 rotToDefStencils_[eIdx].push_back(localDof.dofIndex());
108 }
109 }
111 void init(std::shared_ptr<Problem<rotationIdx>> momentumProblem,
112 std::shared_ptr<Problem<deformationIdx>> massProblem,
113 const SolutionVector& curSol)
114 {
115 this->updateSolution(curSol);
116 this->setSubProblems(std::make_tuple(momentumProblem, massProblem));
117 }
118
123 */
124 void init(std::shared_ptr<Problem<rotationIdx>> momentumProblem,
125 std::shared_ptr<Problem<deformationIdx>> massProblem,
127 {
128 this->attachSolution(curSol);
129 this->setSubProblems(std::make_tuple(momentumProblem, massProblem));
130 }
131
132 template<std::size_t i, std::size_t j>
133 const CouplingStencil<j>& couplingStencil(Dune::index_constant<i> domainI,
134 const Element<i>& element,
135 Dune::index_constant<j> domainJ) const
136 {
137 static_assert(i != j, "A domain cannot be coupled to itself!");
138
139 const auto eIdx = this->problem(domainI).gridGeometry().elementMapper().index(element);
140 if constexpr (domainI == rotationIdx)
141 return rotToDefStencils_[eIdx];
142 else
143 return defToRotStencils_[eIdx];
144 }
146 auto rotation(typename GridGeometry<deformationIdx>::LocalView const& fvGeometry,
147 typename GridGeometry<deformationIdx>::SubControlVolumeFace const& scvf) const
148 {
149 const auto& gg = this->problem(rotationIdx).gridGeometry();
150 const auto elemSol = elementSolution(fvGeometry.element(), curSol(rotationIdx), gg);
151 return evalSolution(
152 fvGeometry.element(),
153 fvGeometry.element().geometry(),
154 gg, elemSol,
155 scvf.ipGlobal()
156 );
157 }
159 auto deformationAndPotentials(typename GridGeometry<rotationIdx>::LocalView const& fvGeometry,
160 typename GridGeometry<rotationIdx>::SubControlVolumeFace const& scvf) const
161 {
162 const auto& gg = this->problem(deformationIdx).gridGeometry();
163 const auto elemSol = elementSolution(fvGeometry.element(), curSol(deformationIdx), gg);
164 return evalSolution(
165 fvGeometry.element(),
166 fvGeometry.element().geometry(),
167 gg, elemSol,
168 scvf.ipGlobal()
169 );
170 }
172 auto shearCurlPotentialIdx() const
173 { return Indices<deformationIdx>::shearCurlPotentialIdx; }
175 auto shearGradPotentialIdx() const
176 { return Indices<deformationIdx>::shearGradPotentialIdx; }
177
183 template<std::size_t i>
184 auto& curSol(Dune::index_constant<i> domainIdx)
185 { return ParentType::curSol(domainIdx); }
186
192 template<std::size_t i>
193 const auto& curSol(Dune::index_constant<i> domainIdx) const
194 { return ParentType::curSol(domainIdx); }
195
200 { elementSets_ = computeColoring(this->problem(deformationIdx).gridGeometry()).sets; }
201
208 template<std::size_t i, class AssembleElementFunc>
209 void assembleMultithreaded(Dune::index_constant<i> domainId, AssembleElementFunc&& assembleElement) const
210 {
211 if (elementSets_.empty())
212 DUNE_THROW(Dune::InvalidStateException,
213 "Call computeColorsForAssembly before assembling in parallel!");
214
215 // make this element loop run in parallel
216 // for this we have to color the elements so that we don't get
217 // race conditions when writing into the global matrix or modifying grid variable caches
218 // each color can be assembled using multiple threads
219 const auto& grid = this->problem(domainId).gridGeometry().gridView().grid();
220 for (const auto& elements : elementSets_)
221 {
222 Dumux::parallelFor(elements.size(), [&](const std::size_t n)
223 {
224 const auto element = grid.entity(elements[n]);
225 assembleElement(element);
226 });
227 }
228 }
229
230private:
232 std::deque<std::vector<ElementSeed<deformationIdx>>> elementSets_;
233
234 std::vector<CouplingStencil<deformationIdx>> rotToDefStencils_;
235 std::vector<CouplingStencil<rotationIdx>> defToRotStencils_;
236};
237
238// we support multithreaded assembly
239template<class MDTraits>
242
243} // end namespace Dumux
244
245#endif
Traits shared by the multi-domain assemblers.
void attachSolution(const SolutionVectorStorage &curSol)
Definition multidomain/couplingmanager.hh:331
void setSubProblems(const std::tuple< std::shared_ptr< SubProblems >... > &problems)
Definition multidomain/couplingmanager.hh:296
const Problem< i > & problem(Dune::index_constant< i > domainIdx) const
Definition multidomain/couplingmanager.hh:318
SubSolutionVector< i > & curSol(Dune::index_constant< i > domainIdx)
Definition multidomain/couplingmanager.hh:347
void updateSolution(const SolutionVector &curSol)
Definition multidomain/couplingmanager.hh:228
CouplingManager()
Definition multidomain/couplingmanager.hh:70
typename MDTraits::template TupleOfSharedPtr< SubSolutionVector > SolutionVectorStorage
Definition multidomain/couplingmanager.hh:59
Definition solidmechanics/plate/kirchhoff_love/couplingmanager.hh:39
void computeStencils(std::shared_ptr< GridGeometry< rotationIdx > > rotationsGG, std::shared_ptr< GridGeometry< deformationIdx > > deformationGG)
(Re-)compute the DOF stencils on the shared mesh of rotationsGG and deformationGG.
Definition solidmechanics/plate/kirchhoff_love/couplingmanager.hh:80
void assembleMultithreaded(Dune::index_constant< i > domainId, AssembleElementFunc &&assembleElement) const
Execute assembly kernel in parallel.
Definition solidmechanics/plate/kirchhoff_love/couplingmanager.hh:208
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:183
void computeColorsForAssembly()
Compute colors for multithreaded assembly.
Definition solidmechanics/plate/kirchhoff_love/couplingmanager.hh:198
typename ParentType::SolutionVectorStorage SolutionVectorStorage
Definition solidmechanics/plate/kirchhoff_love/couplingmanager.hh:66
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:145
auto shearCurlPotentialIdx() const
Definition solidmechanics/plate/kirchhoff_love/couplingmanager.hh:171
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:132
void init(std::shared_ptr< Problem< rotationIdx > > momentumProblem, std::shared_ptr< Problem< deformationIdx > > massProblem, const SolutionVector &curSol)
Definition solidmechanics/plate/kirchhoff_love/couplingmanager.hh:110
auto deformationAndPotentials(typename GridGeometry< rotationIdx >::LocalView const &fvGeometry, typename GridGeometry< rotationIdx >::SubControlVolumeFace const &scvf) const
Definition solidmechanics/plate/kirchhoff_love/couplingmanager.hh:158
static constexpr auto rotationIdx
Definition solidmechanics/plate/kirchhoff_love/couplingmanager.hh:61
auto shearGradPotentialIdx() const
Definition solidmechanics/plate/kirchhoff_love/couplingmanager.hh:174
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:197
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:243
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 assemblytraits.hh:43
Structure to define the index types used for grid and local indices.
Definition indextraits.hh:26