3#ifndef DUNE_PDELAB_LOCALOPERATOR_COMBINEDOPERATOR_HH
4#define DUNE_PDELAB_LOCALOPERATOR_COMBINEDOPERATOR_HH
12#include <dune/pdelab/localoperator/callswitch.hh>
28 template<
typename ApplyOp,
typename... Args>
32 using ArgPtrs = std::tuple<std::shared_ptr<std::remove_reference_t<Args>>...>;
33 using ArgRefs = std::tuple<Args&...>;
37 template<
typename... FArgs>
38 void applyLops(FArgs &... args)
const
40 static_cast<const ApplyOp&
>(*this).applyLops(args...);
54 CombinedOperator(Args&&... args) : lops(std::make_shared<Args>(std::move(args))...) {}
62 template<std::
size_t i>
63 void setSummand(
typename std::tuple_element_t<i,ArgRefs> summand)
64 { std::get<i>(lops) = &summand; }
67 template<std::
size_t i>
69 {
return *std::get<i>(lops); }
82 using OneSidedSkeleton = std::integral_constant
83 < bool, ( ( T::doAlphaSkeleton || T::doLambdaSkeleton) && ! T::doSkeletonTwoSided)>;
85 using TwoSidedSkeleton = std::integral_constant
86 < bool, ( ( T::doAlphaSkeleton || T::doLambdaSkeleton) && T::doSkeletonTwoSided)>;
91 enum { doPatternVolume =
92 std::disjunction_v<std::integral_constant<bool,Args::doPatternVolume>...> };
97 enum { doPatternVolumePostSkeleton =
98 std::disjunction_v<std::integral_constant<bool,Args::doPatternVolumePostSkeleton>...> };
102 enum { doPatternSkeleton =
103 std::disjunction_v<std::integral_constant<bool,Args::doPatternSkeleton>...> };
107 enum { doPatternBoundary =
108 std::disjunction_v<std::integral_constant<bool,Args::doPatternBoundary>...> };
114 enum { doAlphaVolume =
115 std::disjunction_v<std::integral_constant<bool,Args::doAlphaVolume>...> };
120 enum { doAlphaVolumePostSkeleton =
121 std::disjunction_v<std::integral_constant<bool,Args::doAlphaVolumePostSkeleton>...> };
124 enum { doAlphaSkeleton =
125 std::disjunction_v<std::integral_constant<bool,Args::doAlphaSkeleton>...> };
128 enum { doAlphaBoundary =
129 std::disjunction_v<std::integral_constant<bool,Args::doAlphaBoundary>...> };
132 enum { doLambdaVolume =
133 std::disjunction_v<std::integral_constant<bool,Args::doLambdaVolume>...> };
136 enum { doLambdaVolumePostSkeleton =
137 std::disjunction_v<std::integral_constant<bool,Args::doLambdaVolumePostSkeleton>...> };
139 enum { doLambdaSkeleton =
140 std::disjunction_v<std::integral_constant<bool,Args::doLambdaSkeleton>...> };
142 enum { doLambdaBoundary =
143 std::disjunction_v<std::integral_constant<bool,Args::doLambdaBoundary>...> };
146 enum { doSkeletonTwoSided =
147 std::disjunction_v<TwoSidedSkeleton<Args>...> };
148 static_assert(!(std::conjunction_v<OneSidedSkeleton<Args>...> &&
149 std::conjunction_v<TwoSidedSkeleton<Args>...>),
150 "Some summands require a one-sided skelton, others a "
151 "two-sided skeleton. This is not supported.");
154 enum { isLinear = std::conjunction_v<std::integral_constant<bool,Args::isLinear>...> };
170 template<
typename LFSU,
typename LFSV,
typename LocalPattern>
172 (
const LFSU& lfsu,
const LFSV& lfsv,
173 LocalPattern& pattern)
const
175 applyLops(LocalOperatorApply::patternVolume, lfsu, lfsv, pattern);
185 template<
typename LFSU,
typename LFSV,
typename LocalPattern>
187 (
const LFSU& lfsu,
const LFSV& lfsv,
188 LocalPattern& pattern)
const
190 applyLops(LocalOperatorApply::patternVolumePostSkeleton, lfsu, lfsv, pattern);
199 template<
typename LFSU,
typename LFSV,
typename LocalPattern>
201 (
const LFSU& lfsu_s,
const LFSV& lfsv_s,
202 const LFSU& lfsu_n,
const LFSV& lfsv_n,
203 LocalPattern& pattern_sn,
204 LocalPattern& pattern_ns)
const
206 applyLops(LocalOperatorApply::patternSkeleton,
207 lfsu_s, lfsv_s, lfsu_n, lfsv_n,
208 pattern_sn, pattern_ns);
217 template<
typename LFSU,
typename LFSV,
typename LocalPattern>
219 (
const LFSU& lfsu_s,
const LFSV& lfsv_s,
220 LocalPattern& pattern_ss)
const
222 applyLops(LocalOperatorApply::patternBoundary, lfsu_s, lfsv_s, pattern_ss);
238 template<
typename EG,
typename LFSU,
typename X,
typename LFSV,
242 const LFSU& lfsu,
const X& x,
const LFSV& lfsv,
245 applyLops(LocalOperatorApply::alphaVolume, eg, lfsu, x, lfsv, r);
254 template<
typename EG,
typename LFSU,
typename X,
typename LFSV,
258 const LFSU& lfsu,
const X& x,
const LFSV& lfsv,
261 applyLops(LocalOperatorApply::alphaVolumePostSkeleton, eg, lfsu, x, lfsv, r);
269 template<
typename IG,
typename LFSU,
typename X,
typename LFSV,
273 const LFSU& lfsu_s,
const X& x_s,
const LFSV& lfsv_s,
274 const LFSU& lfsu_n,
const X& x_n,
const LFSV& lfsv_n,
275 R& r_s, R& r_n)
const
277 applyLops(LocalOperatorApply::alphaSkeleton, ig,
288 template<
typename IG,
typename LFSU,
typename X,
typename LFSV,
292 const LFSU& lfsu_s,
const X& x_s,
const LFSV& lfsv_s,
295 applyLops(LocalOperatorApply::alphaVolumePostSkeleton, ig, lfsu_s, x_s, lfsv_s, r_s);
311 template<
typename EG,
typename LFSV,
typename R>
314 applyLops(LocalOperatorApply::lambdaVolume, eg, lfsv, r);
323 template<
typename EG,
typename LFSV,
typename R>
328 applyLops(LocalOperatorApply::lambdaVolumePostSkeleton, eg, lfsv, r);
336 template<
typename IG,
typename LFSV,
typename R>
338 const LFSV& lfsv_s,
const LFSV& lfsv_n,
339 R& r_s, R& r_n)
const
341 applyLops(LocalOperatorApply::lambdaSkeleton, ig, lfsv_s, lfsv_n, r_s, r_n);
349 template<
typename IG,
typename LFSV,
typename R>
352 applyLops(LocalOperatorApply::lambdaBoundary, ig, lfsv_s, r_s);
368 template<
typename EG,
typename LFSU,
typename X,
typename LFSV,
372 const LFSU& lfsu,
const X& x,
const LFSV& lfsv,
375 applyLops(LocalOperatorApply::jacobianApplyVolume, eg, lfsu, x, lfsv, y);
384 template<
typename EG,
typename LFSU,
typename X,
typename LFSV,
388 const LFSU& lfsu,
const X& x,
const LFSV& lfsv,
391 applyLops(LocalOperatorApply::jacobianApplyVolumePostSkeleton, eg, lfsu, x, lfsv, y);
399 template<
typename IG,
typename LFSU,
typename X,
typename LFSV,
403 const LFSU& lfsu_s,
const X& x_s,
const LFSV& lfsv_s,
404 const LFSU& lfsu_n,
const X& x_n,
const LFSV& lfsv_n,
405 Y& y_s, Y& y_n)
const
407 applyLops(LocalOperatorApply::jacobianApplySkeleton, ig,
418 template<
typename IG,
typename LFSU,
typename X,
typename LFSV,
422 const LFSU& lfsu_s,
const X& x_s,
const LFSV& lfsv_s,
425 applyLops(LocalOperatorApply::jacobianApplyBoundary, ig, lfsu_s, x_s, lfsv_s, y_s);
441 template<
typename EG,
typename LFSU,
typename X,
typename LFSV,
445 const LFSU& lfsu,
const X& x,
const LFSV& lfsv,
448 applyLops(LocalOperatorApply::jacobianVolume, eg, lfsu, x, lfsv, mat);
456 template<
typename EG,
typename LFSU,
typename X,
typename LFSV,
460 const LFSU& lfsu,
const X& x,
const LFSV& lfsv,
463 applyLops(LocalOperatorApply::jacobianVolumePostSkeleton, eg, lfsu, x, lfsv, mat);
471 template<
typename IG,
typename LFSU,
typename X,
typename LFSV,
475 const LFSU& lfsu_s,
const X& x_s,
const LFSV& lfsv_s,
476 const LFSU& lfsu_n,
const X& x_n,
const LFSV& lfsv_n,
480 applyLops(LocalOperatorApply::jacobianSkeleton, ig,
483 mat_ss, mat_sn, mat_ns, mat_nn);
491 template<
typename IG,
typename LFSU,
typename X,
typename LFSV,
495 const LFSU& lfsu_s,
const X& x_s,
const LFSV& lfsv_s,
498 applyLops(LocalOperatorApply::jacobianBoundary, ig, lfsu_s, x_s, lfsv_s, mat_ss);
510 typedef typename std::tuple_element<0, std::tuple<Args...>>::type::RealType
RealType;
517 template<
typename LOP>
523 template<
typename LOP>
524 static void preStep(
const LOP& lop,
527 lop.preStep(time, dt, stages);
530 template<
typename LOP>
531 static void postStep(
const LOP& lop)
536 template<
typename LOP>
539 lop.preStage(time, r);
542 template<
typename LOP>
548 template<
typename LOP>
551 dt =
std::min(dt,lop.suggestTimestep(dt));
559 applyLops(Apply::setTime, t);
565 return get<0>(lops)->getTime();
571 applyLops(Apply::preStep, time, dt, stages);
577 applyLops(Apply::postStep, lops);
583 applyLops(Apply::preStage, time, r);
589 return get<0>(lops)->getStage();
595 applyLops(Apply::postStage, lops);
606 applyLops(Apply::suggestTimestep, dt);
A local operator to take combine different local operators.
Definition: combinedoperator.hh:30
A dense matrix for storing data associated with the degrees of freedom of a pair of LocalFunctionSpac...
Definition: localmatrix.hh:184
Traits for type conversions and type information.
void jacobian_apply_skeleton(const IG &ig, const LFSU &lfsu_s, const X &x_s, const LFSV &lfsv_s, const LFSU &lfsu_n, const X &x_n, const LFSV &lfsv_n, Y &y_s, Y &y_n) const
apply an internal intersections's jacobians
Definition: combinedoperator.hh:402
void pattern_volume(const LFSU &lfsu, const LFSV &lfsv, LocalPattern &pattern) const
get an element's contribution to the sparsity pattern
Definition: combinedoperator.hh:172
RealType suggestTimestep(RealType dt) const
to be called after stage 1
Definition: combinedoperator.hh:604
RealType getTime() const
get current time
Definition: combinedoperator.hh:563
void jacobian_apply_boundary(const IG &ig, const LFSU &lfsu_s, const X &x_s, const LFSV &lfsv_s, Y &y_s) const
apply a boundary intersections's jacobian
Definition: combinedoperator.hh:421
void lambda_volume(const EG &eg, const LFSV &lfsv, R &r) const
get an element's contribution to lambda
Definition: combinedoperator.hh:312
void pattern_skeleton(const LFSU &lfsu_s, const LFSV &lfsv_s, const LFSU &lfsu_n, const LFSV &lfsv_n, LocalPattern &pattern_sn, LocalPattern &pattern_ns) const
get an internal intersection's contribution to the sparsity pattern
Definition: combinedoperator.hh:201
void jacobian_apply_volume(const EG &eg, const LFSU &lfsu, const X &x, const LFSV &lfsv, Y &y) const
apply an element's jacobian
Definition: combinedoperator.hh:371
void alpha_volume_post_skeleton(const EG &eg, const LFSU &lfsu, const X &x, const LFSV &lfsv, R &r) const
get an element's contribution to alpha after the intersections have been handled
Definition: combinedoperator.hh:257
void pattern_boundary(const LFSU &lfsu_s, const LFSV &lfsv_s, LocalPattern &pattern_ss) const
get a boundary intersection's contribution to the sparsity pattern
Definition: combinedoperator.hh:219
void jacobian_skeleton(const IG &ig, const LFSU &lfsu_s, const X &x_s, const LFSV &lfsv_s, const LFSU &lfsu_n, const X &x_n, const LFSV &lfsv_n, LocalMatrix &mat_ss, LocalMatrix &mat_sn, LocalMatrix &mat_ns, LocalMatrix &mat_nn) const
apply an internal intersections's jacobians
Definition: combinedoperator.hh:474
void postStep()
to be called once at the end of each time step
Definition: combinedoperator.hh:575
void lambda_volume_post_skeleton(const EG &eg, const LFSV &lfsv, R &r) const
get an element's contribution to lambda after the intersections have been handled
Definition: combinedoperator.hh:324
void preStage(RealType time, int r)
to be called once before each stage
Definition: combinedoperator.hh:581
void jacobian_boundary(const IG &ig, const LFSU &lfsu_s, const X &x_s, const LFSV &lfsv_s, LocalMatrix &mat_ss) const
get a boundary intersections's jacobian
Definition: combinedoperator.hh:494
std::tuple_element_t< i, ArgRefs > getSummand()
get the i'th component of the sum
Definition: combinedoperator.hh:68
int getStage() const
get current stage
Definition: combinedoperator.hh:587
void jacobian_volume(const EG &eg, const LFSU &lfsu, const X &x, const LFSV &lfsv, LocalMatrix &mat) const
get an element's jacobian
Definition: combinedoperator.hh:444
void alpha_skeleton(const IG &ig, const LFSU &lfsu_s, const X &x_s, const LFSV &lfsv_s, const LFSU &lfsu_n, const X &x_n, const LFSV &lfsv_n, R &r_s, R &r_n) const
get an internal intersections's contribution to alpha
Definition: combinedoperator.hh:272
void postStage()
to be called once at the end of each stage
Definition: combinedoperator.hh:593
void setSummand(typename std::tuple_element_t< i, ArgRefs > summand)
set the i'th component of the sum
Definition: combinedoperator.hh:63
void pattern_volume_post_skeleton(const LFSU &lfsu, const LFSV &lfsv, LocalPattern &pattern) const
get an element's contribution to the sparsity pattern after the intersections have been handled
Definition: combinedoperator.hh:187
std::tuple_element< 0, std::tuple< Args... > >::type::RealType RealType
Export type used for time values.
Definition: combinedoperator.hh:510
void preStep(RealType time, RealType dt, int stages)
to be called once before each time step
Definition: combinedoperator.hh:569
void lambda_skeleton(const IG &ig, const LFSV &lfsv_s, const LFSV &lfsv_n, R &r_s, R &r_n) const
get an internal intersections's contribution to lambda
Definition: combinedoperator.hh:337
void lambda_boundary(const IG &ig, const LFSV &lfsv_s, R &r_s) const
get a boundary intersections's contribution to lambda
Definition: combinedoperator.hh:350
void jacobian_volume_post_skeleton(const EG &eg, const LFSU &lfsu, const X &x, const LFSV &lfsv, LocalMatrix &mat) const
get an element's jacobian after the intersections have been handled
Definition: combinedoperator.hh:459
void setTime(RealType t)
set time for subsequent evaluation
Definition: combinedoperator.hh:557
void jacobian_apply_volume_post_skeleton(const EG &eg, const LFSU &lfsu, const X &x, const LFSV &lfsv, Y &y) const
apply an element's jacobian after the intersections have been handled
Definition: combinedoperator.hh:387
void alpha_boundary(const IG &ig, const LFSU &lfsu_s, const X &x_s, const LFSV &lfsv_s, R &r_s) const
get a boundary intersections's contribution to alpha
Definition: combinedoperator.hh:291
void alpha_volume(const EG &eg, const LFSU &lfsu, const X &x, const LFSV &lfsv, R &r) const
get an element's contribution to alpha
Definition: combinedoperator.hh:241
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:87
Dune namespace.
Definition: alignedallocator.hh:14
shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:75
Contains utility classes which can be used with std::tuple.