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 <vector>
26#include <dune/common/fmatrix.hh>
30
31namespace Dumux {
32
39template<class MDTraits>
41{
42 using ParentType = CouplingManager<MDTraits>;
43
44 template<std::size_t id> using SubDomainTypeTag = typename MDTraits::template SubDomain<id>::TypeTag;
45 template<std::size_t id> using GridGeometry = GetPropType<SubDomainTypeTag<id>, Properties::GridGeometry>;
46 template<std::size_t id> using GridView = typename GridGeometry<id>::GridView;
47 template<std::size_t id> using Element = typename GridView<id>::template Codim<0>::Entity;
48 template<std::size_t id> using ElementSeed = typename GridView<id>::Grid::template Codim<0>::EntitySeed;
49
50 using Scalar = typename MDTraits::Scalar;
51 using SolutionVector = typename MDTraits::SolutionVector;
52
53 static constexpr std::size_t momIdx_ = 0;
54 static constexpr std::size_t presIdx_ = 1;
55
56 using GlobalPosition = typename Element<0>::Geometry::GlobalCoordinate;
57 using Tensor = Dune::FieldMatrix<Scalar, GridView<0>::dimension, GridView<0>::dimension>;
58 static constexpr int dim = GridView<0>::dimension;
59
60public:
61 static constexpr auto momentumIdx = Dune::index_constant<momIdx_>();
62 static constexpr auto pressureIdx = Dune::index_constant<presIdx_>();
63
64 using CouplingStencilType = std::vector<std::size_t>;
65
67 std::shared_ptr<GridGeometry<momIdx_>> momGG,
68 std::shared_ptr<GridGeometry<presIdx_>> presGG)
69 {
70 buildStencils_(*momGG, *presGG);
71 }
72
73 void init(std::shared_ptr<GetPropType<SubDomainTypeTag<momIdx_>, Properties::Problem>> momProblem,
74 std::shared_ptr<GetPropType<SubDomainTypeTag<presIdx_>, Properties::Problem>> presProblem,
75 const SolutionVector& curSol)
76 {
78 this->setSubProblems(std::make_tuple(momProblem, presProblem));
79 }
80
81 template<std::size_t i, std::size_t j>
82 const CouplingStencilType& couplingStencil(Dune::index_constant<i>,
83 const Element<j>& element,
84 Dune::index_constant<j>) const
85 {
86 static_assert(i != j);
87 const auto eIdx = this->problem(Dune::index_constant<j>{})
88 .gridDiscretization().elementMapper().index(element);
89 if constexpr (i == momIdx_) return stencilsMomToPres_[eIdx];
90 else return stencilsPresTOMom_[eIdx];
91 }
92
94 Scalar pressureAtPoint(const typename GridGeometry<momIdx_>::LocalView& fvGeom,
95 const GlobalPosition& ip) const
96 {
97 const auto& gg = this->problem(pressureIdx).gridDiscretization();
98 const auto elemSol = elementSolution(fvGeom.element(), this->curSol(pressureIdx), gg);
99 return evalSolution(fvGeom.element(), fvGeom.element().geometry(),
100 gg, elemSol, ip)[0];
101 }
102
104 Tensor deformationGradientAtPoint(const typename GridGeometry<presIdx_>::LocalView& fvGeom,
105 const GlobalPosition& ip) const
106 {
107 const auto& gg = this->problem(momentumIdx).gridDiscretization();
108 const auto fvGeomMom = localView(gg).bindElement(fvGeom.element());
109 return computeF_(fvGeom.element(), ip, fvGeomMom);
110 }
111
113 {
114 elementSets_ = computeColoring(
116 }
117
118 template<std::size_t i, class AssembleElementFunc>
119 void assembleMultithreaded(Dune::index_constant<i>, AssembleElementFunc&& f) const
120 {
121 if (elementSets_.empty())
122 DUNE_THROW(Dune::InvalidStateException,
123 "Call computeColorsForAssembly before parallel assembly!");
124 const auto& grid = this->problem(Dune::index_constant<i>{})
125 .gridDiscretization().gridView().grid();
126 for (const auto& elems : elementSets_)
127 Dumux::parallelFor(elems.size(), [&](std::size_t n)
128 { f(grid.entity(elems[n])); });
129 }
130
131 template<std::size_t i>
132 auto& curSol(Dune::index_constant<i> id) { return ParentType::curSol(id); }
133 template<std::size_t i>
134 const auto& curSol(Dune::index_constant<i> id) const { return ParentType::curSol(id); }
135
136private:
137 Tensor computeF_(const Element<presIdx_>& element,
138 const GlobalPosition& ip,
139 const typename GridGeometry<momIdx_>::LocalView& fvGeomMom) const
140 {
141 const auto& geom = element.geometry();
142 const auto ipLocal = geom.local(ip);
143 const auto& localBasis = fvGeomMom.feLocalBasis();
144 using ShapeJac = typename std::decay_t<decltype(localBasis)>::Traits::JacobianType;
145 std::vector<ShapeJac> shapeJac;
146 localBasis.evaluateJacobian(ipLocal, shapeJac);
147 const auto jacInvT = geom.jacobianInverseTransposed(ipLocal);
148
149 Tensor F(0.0);
150 for (const auto& localDof : localDofs(fvGeomMom))
151 {
152 GlobalPosition gradN;
153 jacInvT.mv(shapeJac[localDof.index()][0], gradN);
154 for (int d = 0; d < dim; ++d)
155 F[d].axpy(this->curSol(momentumIdx)[localDof.dofIndex()][d], gradN);
156 }
157 for (int d = 0; d < dim; ++d) F[d][d] += 1.0;
158 return F;
159 }
160
161 void buildStencils_(const GridGeometry<momIdx_>& momGG, const GridGeometry<presIdx_>& presGG)
162 {
163 const std::size_t n = presGG.gridView().size(0);
164 stencilsMomToPres_.resize(n);
165 stencilsPresTOMom_.resize(n);
166
167 auto fvMom = localView(momGG);
168 auto fvPres = localView(presGG);
169
170 for (const auto& element : elements(presGG.gridView()))
171 {
172 fvMom.bindElement(element);
173 fvPres.bindElement(element);
174 const std::size_t eIdx = presGG.elementMapper().index(element);
175
176 for (const auto& localDof : localDofs(fvPres))
177 stencilsMomToPres_[eIdx].push_back(localDof.dofIndex());
178 // Use localDofs (not scvs) to include non-SCV DOFs (e.g. PQ2 edge midpoints)
179 for (const auto& localDof : localDofs(fvMom))
180 stencilsPresTOMom_[eIdx].push_back(localDof.dofIndex());
181 }
182 }
183
184 std::deque<std::vector<ElementSeed<momIdx_>>> elementSets_;
185 std::vector<CouplingStencilType> stencilsMomToPres_, stencilsPresTOMom_;
186};
187
188template<class MDTraits>
191
192} // end namespace Dumux
193#endif
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 u–p hyperelastic model.
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:41
static constexpr auto momentumIdx
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:61
Tensor deformationGradientAtPoint(const typename GridGeometry< presIdx_ >::LocalView &fvGeom, const GlobalPosition &ip) const
Evaluate at a global position (displacement shape functions).
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:104
auto & curSol(Dune::index_constant< i > id)
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:132
std::vector< std::size_t > CouplingStencilType
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:64
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:73
const auto & curSol(Dune::index_constant< i > id) const
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:134
void computeColorsForAssembly()
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:112
static constexpr auto pressureIdx
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:62
void assembleMultithreaded(Dune::index_constant< i >, AssembleElementFunc &&f) const
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:119
const CouplingStencilType & couplingStencil(Dune::index_constant< i >, const Element< j > &element, Dune::index_constant< j >) const
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:82
Scalar pressureAtPoint(const typename GridGeometry< momIdx_ >::LocalView &fvGeom, const GlobalPosition &ip) const
Evaluate at a global position (P1 interpolation from pressure solution).
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:94
HyperelasticVolIsoCouplingManager(std::shared_ptr< GridGeometry< momIdx_ > > momGG, std::shared_ptr< GridGeometry< presIdx_ > > presGG)
Definition solidmechanics/hyperelastic_voliso/couplingmanager.hh:66
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
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
Type trait that is specialized for coupling manager supporting multithreaded assembly.
Definition assemblytraits.hh:43