version 3.11-dev
Loading...
Searching...
No Matches
solidmechanics/hyperelastic_voliso/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//
22#ifndef DUMUX_SOLIDMECHANICS_HYPERELASTIC_VOLISO_COUPLING_MANAGER_HH
23#define DUMUX_SOLIDMECHANICS_HYPERELASTIC_VOLISO_COUPLING_MANAGER_HH
24
25#include <deque>
26#include <memory>
27#include <tuple>
28#include <type_traits>
29#include <vector>
30
31#include <dune/common/exceptions.hh>
32#include <dune/common/fmatrix.hh>
33#include <dune/common/indices.hh>
34
36#include <dumux/common/concepts/ipdata_.hh>
43
44namespace Dumux {
45
52template<class MDTraits>
54{
55 using ParentType = CouplingManager<MDTraits>;
56
57 template<std::size_t id> using SubDomainTypeTag = typename MDTraits::template SubDomain<id>::TypeTag;
58 template<std::size_t id> using GridDiscretization = GetPropType<SubDomainTypeTag<id>, Properties::GridGeometry>;
59 template<std::size_t id> using ElementDiscretization = typename GridDiscretization<id>::LocalView;
60 template<std::size_t id> using GridView = typename GridDiscretization<id>::GridView;
61 template<std::size_t id> using Element = typename GridView<id>::template Codim<0>::Entity;
62 template<std::size_t id> using ElementSeed = typename GridView<id>::Grid::template Codim<0>::EntitySeed;
63
64 using Scalar = typename MDTraits::Scalar;
65 using SolutionVector = typename MDTraits::SolutionVector;
66
67 static constexpr std::size_t momIdx_ = 0;
68 static constexpr std::size_t presIdx_ = 1;
69
70 using GlobalPosition = typename Element<0>::Geometry::GlobalCoordinate;
71 using LocalPosition = typename Element<0>::Geometry::LocalCoordinate;
72 using Tensor = Dune::FieldMatrix<Scalar, GridView<0>::dimension, GridView<0>::dimension>;
73 static constexpr int dim = GridView<0>::dimension;
74
75public:
76 static constexpr auto momentumIdx = Dune::index_constant<momIdx_>();
77 static constexpr auto pressureIdx = Dune::index_constant<presIdx_>();
78
79 using CouplingStencilType = std::vector<std::size_t>;
80
82 std::shared_ptr<GridDiscretization<momIdx_>> momGridDisc,
83 std::shared_ptr<GridDiscretization<presIdx_>> presGridDisc)
84 {
85 buildStencils_(*momGridDisc, *presGridDisc);
86 }
87
88 void init(std::shared_ptr<GetPropType<SubDomainTypeTag<momIdx_>, Properties::Problem>> momProblem,
89 std::shared_ptr<GetPropType<SubDomainTypeTag<presIdx_>, Properties::Problem>> presProblem,
90 const SolutionVector& curSol)
91 {
93 this->setSubProblems(std::make_tuple(momProblem, presProblem));
94 }
95
96 template<std::size_t i, std::size_t j>
97 const CouplingStencilType& couplingStencil(Dune::index_constant<i>,
98 const Element<j>& element,
99 Dune::index_constant<j>) const
100 {
101 static_assert(i != j);
102 const auto eIdx = this->problem(Dune::index_constant<j>{})
103 .gridDiscretization().elementMapper().index(element);
104 if constexpr (i == momIdx_) return stencilsMomToPres_[eIdx];
105 else return stencilsPresTOMom_[eIdx];
106 }
107
108 template<Concept::IpData IpData>
109 Scalar pressure(const ElementDiscretization<momIdx_>& elemDisc,
110 const IpData& ipData) const
111 {
112 const auto& gridDisc = this->problem(pressureIdx).gridDiscretization();
113 const auto elemSol = elementSolution(elemDisc.element(), this->curSol(pressureIdx), gridDisc);
114 return evalSolutionAtLocalPos(elemDisc.element(), elemDisc.element().geometry(),
115 gridDisc, elemSol, ipData.local())[0];
116 }
117
118 template<Concept::IpData IpData>
119 Tensor deformationGradient(const ElementDiscretization<presIdx_>& elemDisc,
120 const IpData& ipData) const
121 {
122 const auto& gridDisc = this->problem(momentumIdx).gridDiscretization();
123 const auto elemDiscMom = localView(gridDisc).bindElement(elemDisc.element());
124 return computeF_(elemDisc.element(), ipData.local(), elemDiscMom);
125 }
126
128 {
129 elementSets_ = computeColoring(
131 }
132
133 template<std::size_t i, class AssembleElementFunc>
134 void assembleMultithreaded(Dune::index_constant<i>, AssembleElementFunc&& f) const
135 {
136 if (elementSets_.empty())
137 DUNE_THROW(Dune::InvalidStateException,
138 "Call computeColorsForAssembly before parallel assembly!");
139 const auto& grid = this->problem(Dune::index_constant<i>{})
140 .gridDiscretization().gridView().grid();
141 for (const auto& elems : elementSets_)
142 Dumux::parallelFor(elems.size(), [&](std::size_t n)
143 { f(grid.entity(elems[n])); });
144 }
145
146 template<std::size_t i>
147 auto& curSol(Dune::index_constant<i> id) { return ParentType::curSol(id); }
148 template<std::size_t i>
149 const auto& curSol(Dune::index_constant<i> id) const { return ParentType::curSol(id); }
150
151private:
152 Tensor computeF_(const Element<presIdx_>& element,
153 const LocalPosition& ipLocal,
154 const ElementDiscretization<momIdx_>& elemDiscMom) const
155 {
156 const auto& geom = element.geometry();
157 const auto& localBasis = elemDiscMom.feLocalBasis();
158 using ShapeJac = typename std::decay_t<decltype(localBasis)>::Traits::JacobianType;
159 std::vector<ShapeJac> shapeJac;
160 localBasis.evaluateJacobian(ipLocal, shapeJac);
161 const auto jacInvT = geom.jacobianInverseTransposed(ipLocal);
162
163 Tensor F(0.0);
164 for (const auto& localDof : localDofs(elemDiscMom))
165 {
166 GlobalPosition gradN;
167 jacInvT.mv(shapeJac[localDof.index()][0], gradN);
168 for (int d = 0; d < dim; ++d)
169 F[d].axpy(this->curSol(momentumIdx)[localDof.dofIndex()][d], gradN);
170 }
171 for (int d = 0; d < dim; ++d) F[d][d] += 1.0;
172 return F;
173 }
174
175 void buildStencils_(const GridDiscretization<momIdx_>& momGridDisc,
176 const GridDiscretization<presIdx_>& presGridDisc)
177 {
178 const std::size_t n = presGridDisc.gridView().size(0);
179 stencilsMomToPres_.resize(n);
180 stencilsPresTOMom_.resize(n);
181
182 auto elemDiscMom = localView(momGridDisc);
183 auto elemDiscPres = localView(presGridDisc);
184
185 for (const auto& element : elements(presGridDisc.gridView()))
186 {
187 elemDiscMom.bindElement(element);
188 elemDiscPres.bindElement(element);
189 const std::size_t eIdx = presGridDisc.elementMapper().index(element);
190
191 for (const auto& localDof : localDofs(elemDiscPres))
192 stencilsMomToPres_[eIdx].push_back(localDof.dofIndex());
193 // Use localDofs (not scvs) to include non-SCV DOFs (e.g. PQ2 edge midpoints)
194 for (const auto& localDof : localDofs(elemDiscMom))
195 stencilsPresTOMom_[eIdx].push_back(localDof.dofIndex());
196 }
197 }
198
199 std::deque<std::vector<ElementSeed<momIdx_>>> elementSets_;
200 std::vector<CouplingStencilType> stencilsMomToPres_, stencilsPresTOMom_;
201};
202
203template<class MDTraits>
206
207} // end namespace Dumux
208#endif
Traits shared by the multi-domain assemblers.
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
Coupling manager for the mixed – hyperelastic model.
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:54
static constexpr auto momentumIdx
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:76
auto & curSol(Dune::index_constant< i > id)
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:147
std::vector< std::size_t > CouplingStencilType
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:79
HyperelasticVolIsoCouplingManager(std::shared_ptr< GridDiscretization< momIdx_ > > momGridDisc, std::shared_ptr< GridDiscretization< presIdx_ > > presGridDisc)
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:81
void init(std::shared_ptr< GetPropType< SubDomainTypeTag< momIdx_ >, Properties::Problem > > momProblem, std::shared_ptr< GetPropType< SubDomainTypeTag< presIdx_ >, Properties::Problem > > presProblem, const SolutionVector &curSol)
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:88
Scalar pressure(const ElementDiscretization< momIdx_ > &elemDisc, const IpData &ipData) const
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:109
const auto & curSol(Dune::index_constant< i > id) const
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:149
void computeColorsForAssembly()
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:127
Tensor deformationGradient(const ElementDiscretization< presIdx_ > &elemDisc, const IpData &ipData) const
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:119
static constexpr auto pressureIdx
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:77
void assembleMultithreaded(Dune::index_constant< i >, AssembleElementFunc &&f) const
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:134
const CouplingStencilType & couplingStencil(Dune::index_constant< i >, const Element< j > &element, Dune::index_constant< j >) const
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:97
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
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
PrimaryVariables evalSolutionAtLocalPos(const Element &element, const typename Element::Geometry &geometry, const typename FVElementGeometry::GridGeometry &gridGeometry, const CVFEElementSolution< FVElementGeometry, PrimaryVariables > &elemSol, const typename Element::Geometry::LocalCoordinate &localPos, bool ignoreState=false)
Interpolates a given cvfe element solution at a given local position. Uses the finite element cache o...
Definition evalsolution.hh:172
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
decltype(auto) gridDiscretization(const T &t, Args &&... args)
The grid discretization.
Definition griddiscretization.hh:65
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