version 3.11-dev
Loading...
Searching...
No Matches
multidomain/assembler.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//
14#ifndef DUMUX_MULTIDOMAIN_ASSEMBLER_HH
15#define DUMUX_MULTIDOMAIN_ASSEMBLER_HH
16
17#include <algorithm>
18#include <cassert>
19#include <iostream>
20#include <type_traits>
21#include <tuple>
22
23#include <dune/common/hybridutilities.hh>
24#include <dune/istl/matrixindexset.hh>
25
34#include <dumux/common/concepts/variables_.hh>
39
42#include "subdomaincvfelocalassembler_.hh"
45#include "assemblerview.hh"
46#include "assemblytraits.hh"
47
49#if HAVE_DUMUX_OLD_STAGGERED
50#include <dumux/multidomain/subdomainstaggeredlocalassembler.hh>
51#endif
52
53namespace Dumux::Experimental {
54
64template<class MDTraits, class CMType, DiffMethod diffMethod, bool useImplicitAssembly = true>
66{
67 template<std::size_t id>
68 using SubDomainTypeTag = typename MDTraits::template SubDomain<id>::TypeTag;
69
70public:
71 using Traits = MDTraits;
72
73 using Scalar = typename MDTraits::Scalar;
74
75 template<std::size_t id>
76 using LocalResidual = typename MDTraits::template SubDomain<id>::LocalResidual;
77
78 template<std::size_t id>
79 using GridVariables = typename MDTraits::template SubDomain<id>::GridVariables;
80
81 template<std::size_t id>
82 using GridDiscretization = GetPropType<SubDomainTypeTag<id>, Properties::GridGeometry>;
83
84 template<std::size_t id>
85 using Problem = typename MDTraits::template SubDomain<id>::Problem;
86
87 using JacobianMatrix = typename MDTraits::JacobianMatrix;
88 using SolutionVector = typename MDTraits::SolutionVector;
89 using ResidualType = typename MDTraits::ResidualVector;
90
91 using CouplingManager = CMType;
92
96 static constexpr bool isImplicit()
97 { return useImplicitAssembly; }
98
99private:
100
101 using ProblemTuple = typename MDTraits::template TupleOfSharedPtrConst<Problem>;
102 using GridDiscretizationTuple = typename MDTraits::template TupleOfSharedPtrConst<GridDiscretization>;
103 using GridVariablesTuple = typename MDTraits::template TupleOfSharedPtr<GridVariables>;
104
106 using ThisType = MultiDomainAssembler<MDTraits, CouplingManager, diffMethod, isImplicit()>;
107
108 template<std::size_t id>
109 using SubDomainAssemblerView = MultiDomainAssemblerSubDomainView<ThisType, id>;
110
111 template<class DiscretizationMethod, std::size_t id>
112 struct SubDomainAssemblerType;
113
114 template<std::size_t id>
115 struct SubDomainAssemblerType<DiscretizationMethods::CCTpfa, id>
116 {
117 using type = SubDomainCCLocalAssembler<id, SubDomainTypeTag<id>, SubDomainAssemblerView<id>, diffMethod, isImplicit()>;
118 };
119
120 template<std::size_t id>
121 struct SubDomainAssemblerType<DiscretizationMethods::CCMpfa, id>
122 {
123 using type = SubDomainCCLocalAssembler<id, SubDomainTypeTag<id>, SubDomainAssemblerView<id>, diffMethod, isImplicit()>;
124 };
125
126 template<std::size_t id, class DM>
127 struct SubDomainAssemblerType<DiscretizationMethods::CVFE<DM>, id>
128 {
129 private:
130 using GV = GridVariables<id>;
131 static constexpr bool usesGeneralGridVariables =
132 Dumux::Concept::GridVariables<GV> && !Dumux::Concept::FVGridVariables<GV>;
133 public:
134 using type = std::conditional_t<usesGeneralGridVariables,
136 Dumux::SubDomainCVFELocalAssembler<id, SubDomainTypeTag<id>, SubDomainAssemblerView<id>, diffMethod, isImplicit()>>;
137 };
138
139#if HAVE_DUMUX_OLD_STAGGERED
140 template<std::size_t id>
141 struct SubDomainAssemblerType<DiscretizationMethods::Staggered, id>
142 {
143 using type = SubDomainStaggeredLocalAssembler<id, SubDomainTypeTag<id>, SubDomainAssemblerView<id>, diffMethod, isImplicit()>;
144 };
145#endif
146
147 template<std::size_t id>
148 struct SubDomainAssemblerType<DiscretizationMethods::FCStaggered, id>
149 {
150 using type = SubDomainFaceCenteredLocalAssembler<id, SubDomainTypeTag<id>, SubDomainAssemblerView<id>, diffMethod, isImplicit()>;
151 };
152
153 template<std::size_t id>
154 using SubDomainAssembler = typename SubDomainAssemblerType<typename GridDiscretization<id>::DiscretizationMethod, id>::type;
155
156public:
157
164 GridDiscretizationTuple gridDiscretization,
165 GridVariablesTuple gridVariables,
166 std::shared_ptr<CouplingManager> couplingManager)
168 , problemTuple_(std::move(problem))
169 , gridDiscretizationTuple_(std::move(gridDiscretization))
170 , gridVariablesTuple_(std::move(gridVariables))
171 , timeLoop_()
172 , isStationaryProblem_(true)
173 , warningIssued_(false)
174 {
175 static_assert(isImplicit(), "Explicit assembler for stationary problem doesn't make sense!");
176 std::cout << "Instantiated assembler for a stationary problem." << std::endl;
177
179 && Grid::Capabilities::allGridsSupportsMultithreading(gridDiscretizationTuple_)
181 && getParam<bool>("Assembly.Multithreading", true);
182
183 maybeComputeColors_();
184 }
185
192 GridDiscretizationTuple gridDiscretization,
193 GridVariablesTuple gridVariables,
194 std::shared_ptr<CouplingManager> couplingManager,
195 std::shared_ptr<const TimeLoop> timeLoop,
196 const SolutionVector& prevSol)
198 , problemTuple_(std::move(problem))
199 , gridDiscretizationTuple_(std::move(gridDiscretization))
200 , gridVariablesTuple_(std::move(gridVariables))
201 , timeLoop_(timeLoop)
202 , prevSol_(&prevSol)
203 , isStationaryProblem_(false)
204 , warningIssued_(false)
205 {
206 std::cout << "Instantiated assembler for an instationary problem." << std::endl;
207
209 && Grid::Capabilities::allGridsSupportsMultithreading(gridDiscretizationTuple_)
211 && getParam<bool>("Assembly.Multithreading", true);
212
213 maybeComputeColors_();
214 }
215
221 {
222 checkAssemblerState_();
223 resetJacobian_();
224 resetResidual_();
225
226 using namespace Dune::Hybrid;
227 forEach(std::make_index_sequence<JacobianMatrix::N()>(), [&](const auto domainId)
228 {
229 auto& jacRow = (*jacobian_)[domainId];
230 auto& subRes = (*residual_)[domainId];
231 const auto& subSol = curSol[domainId];
232 this->assembleJacobianAndResidual_(domainId, jacRow, subRes, curSol);
233
234 const auto gridDiscretization = std::get<domainId>(gridDiscretizationTuple_);
235 enforcePeriodicConstraints_(domainId, jacRow, subRes, *gridDiscretization, subSol);
236 enforceProblemConstraints_(domainId, jacRow, subRes, *gridDiscretization, subSol);
237 });
238 }
239
242 {
243 resetResidual_();
244 assembleResidual(*residual_, curSol);
245 }
246
249 {
250 r = 0.0;
251
252 checkAssemblerState_();
253
254 // update the grid variables for the case of active caching
255 updateGridVariables(curSol);
256
257 using namespace Dune::Hybrid;
258 forEach(integralRange(Dune::Hybrid::size(r)), [&](const auto domainId)
259 {
260 auto& subRes = r[domainId];
261 const auto& subSol = curSol[domainId];
262 this->assembleResidual_(domainId, subRes, curSol);
263
264 const auto gridDiscretization = std::get<domainId>(gridDiscretizationTuple_);
265 enforcePeriodicConstraints_(domainId, subRes, *gridDiscretization, subSol);
266 enforceProblemConstraints_(domainId, subRes, *gridDiscretization, subSol);
267 });
268 }
269
275 void setLinearSystem(std::shared_ptr<JacobianMatrix> A,
276 std::shared_ptr<ResidualType> r)
277 {
278 jacobian_ = A;
279 residual_ = r;
280
281 setJacobianBuildMode(*jacobian_);
282 setJacobianPattern_(*jacobian_);
283 setResidualSize_(*residual_);
284 }
285
291 {
292 jacobian_ = std::make_shared<JacobianMatrix>();
293 residual_ = std::make_shared<ResidualType>();
294
295 setJacobianBuildMode(*jacobian_);
296 setJacobianPattern_(*jacobian_);
297 setResidualSize_(*residual_);
298 }
299
304 {
305 using namespace Dune::Hybrid;
306 forEach(std::make_index_sequence<JacobianMatrix::N()>(), [&](const auto i)
307 {
308 forEach(jac[i], [&](auto& jacBlock)
309 {
310 using BlockType = std::decay_t<decltype(jacBlock)>;
311 if (jacBlock.buildMode() == BlockType::BuildMode::unknown)
312 jacBlock.setBuildMode(BlockType::BuildMode::random);
313 else if (jacBlock.buildMode() != BlockType::BuildMode::random)
314 DUNE_THROW(Dune::NotImplemented, "Only BCRS matrices with random build mode are supported at the moment");
315 });
316 });
317 }
318
323 {
324 setJacobianPattern_(*jacobian_);
325 setResidualSize_(*residual_);
326 maybeComputeColors_();
327 }
328
333 {
334 using namespace Dune::Hybrid;
335 forEach(integralRange(Dune::Hybrid::size(gridVariablesTuple_)), [&](const auto domainId)
336 { this->gridVariables(domainId).update(curSol[domainId]); });
337 }
338
342 void resetTimeStep(const SolutionVector& curSol)
343 {
344 using namespace Dune::Hybrid;
345 forEach(integralRange(Dune::Hybrid::size(gridVariablesTuple_)), [&](const auto domainId)
346 { this->gridVariables(domainId).resetTimeStep(curSol[domainId]); });
347 }
348
350 template<std::size_t i>
351 std::size_t numDofs(Dune::index_constant<i> domainId) const
352 { return std::get<domainId>(gridDiscretizationTuple_)->numDofs(); }
353
355 template<std::size_t i>
356 const auto& problem(Dune::index_constant<i> domainId) const
357 { return *std::get<domainId>(problemTuple_); }
358
360 template<std::size_t i>
361 const auto& gridDiscretization(Dune::index_constant<i> domainId) const
362 { return *std::get<domainId>(gridDiscretizationTuple_); }
363
365 template<std::size_t i>
366 const auto& gridView(Dune::index_constant<i> domainId) const
367 { return gridDiscretization(domainId).gridView(); }
368
370 template<std::size_t i>
371 GridVariables<i>& gridVariables(Dune::index_constant<i> domainId)
372 { return *std::get<domainId>(gridVariablesTuple_); }
373
375 template<std::size_t i>
376 const GridVariables<i>& gridVariables(Dune::index_constant<i> domainId) const
377 { return *std::get<domainId>(gridVariablesTuple_); }
378
381 { return *couplingManager_; }
382
385 { return *jacobian_; }
386
389 { return *residual_; }
390
392 const SolutionVector& prevSol() const
393 { return *prevSol_; }
394
399 void setTimeLoop(std::shared_ptr<const TimeLoop> timeLoop)
400 { timeLoop_ = timeLoop; isStationaryProblem_ = !(static_cast<bool>(timeLoop)); }
401
403 [[deprecated("Will be removed after release 3.11. Use setTimeLoop")]]
404 void setTimeManager(std::shared_ptr<const TimeLoop> timeLoop)
405 { setTimeLoop(timeLoop); }
406
412 { prevSol_ = &u; }
413
418 { return isStationaryProblem_; }
419
423 template<std::size_t i>
424 LocalResidual<i> localResidual(Dune::index_constant<i> domainId) const
425 { return LocalResidual<i>(std::get<domainId>(problemTuple_).get(), timeLoop_.get()); }
426
427protected:
429 std::shared_ptr<CouplingManager> couplingManager_;
430
431private:
435 void setJacobianPattern_(JacobianMatrix& jac) const
436 {
437 using namespace Dune::Hybrid;
438 forEach(std::make_index_sequence<JacobianMatrix::N()>(), [&](const auto domainI)
439 {
440 forEach(integralRange(Dune::Hybrid::size(jac[domainI])), [&](const auto domainJ)
441 {
442 const auto pattern = this->getJacobianPattern_(domainI, domainJ);
443 pattern.exportIdx(jac[domainI][domainJ]);
444 });
445 });
446 }
447
451 void setResidualSize_(ResidualType& res) const
452 {
453 using namespace Dune::Hybrid;
454 forEach(integralRange(Dune::Hybrid::size(res)), [&](const auto domainId)
455 { res[domainId].resize(this->numDofs(domainId)); });
456 }
457
458 // reset the residual vector to 0.0
459 void resetResidual_()
460 {
461 if(!residual_)
462 {
463 residual_ = std::make_shared<ResidualType>();
464 setResidualSize_(*residual_);
465 }
466
467 (*residual_) = 0.0;
468 }
469
470 // reset the jacobian vector to 0.0
471 void resetJacobian_()
472 {
473 if(!jacobian_)
474 {
475 jacobian_ = std::make_shared<JacobianMatrix>();
476 setJacobianBuildMode(*jacobian_);
477 setJacobianPattern_(*jacobian_);
478 }
479
480 (*jacobian_) = 0.0;
481 }
482
484 void maybeComputeColors_()
485 {
486 if constexpr (CouplingManagerSupportsMultithreadedAssembly<CouplingManager>::value)
487 if (enableMultithreading_)
488 couplingManager_->computeColorsForAssembly();
489 }
490
491 // check if the assembler is in a correct state for assembly
492 void checkAssemblerState_() const
493 {
494 if (!isStationaryProblem_ && !prevSol_)
495 DUNE_THROW(Dune::InvalidStateException, "Assembling instationary problem but previous solution was not set!");
496
497 if (isStationaryProblem_ && prevSol_)
498 DUNE_THROW(Dune::InvalidStateException, "Assembling stationary problem but a previous solution was set."
499 << " Did you forget to set the timeLoop to make this problem instationary?");
500 }
501
502 template<std::size_t i, class JacRow, class SubRes>
503 void assembleJacobianAndResidual_(Dune::index_constant<i> domainId, JacRow& jacRow, SubRes& subRes,
504 const SolutionVector& curSol)
505 {
506 assemble_(domainId, [&](const auto& element)
507 {
508 MultiDomainAssemblerSubDomainView view{*this, domainId};
509 SubDomainAssembler<i> subDomainAssembler(view, element, curSol, *couplingManager_);
510 subDomainAssembler.assembleJacobianAndResidual(jacRow, subRes, gridVariablesTuple_);
511 });
512 }
513
514 template<std::size_t i, class SubRes>
515 void assembleResidual_(Dune::index_constant<i> domainId, SubRes& subRes,
516 const SolutionVector& curSol)
517 {
518 assemble_(domainId, [&](const auto& element)
519 {
520 MultiDomainAssemblerSubDomainView view{*this, domainId};
521 SubDomainAssembler<i> subDomainAssembler(view, element, curSol, *couplingManager_);
522 subDomainAssembler.assembleResidual(subRes);
523 });
524 }
525
531 template<std::size_t i, class AssembleElementFunc>
532 void assemble_(Dune::index_constant<i> domainId, AssembleElementFunc&& assembleElement) const
533 {
534 // a state that will be checked on all processes
535 bool succeeded = false;
536
537 // try assembling using the local assembly function
538 try
539 {
540 if constexpr (CouplingManagerSupportsMultithreadedAssembly<CouplingManager>::value)
541 {
542 if (enableMultithreading_)
543 {
544 couplingManager_->assembleMultithreaded(
545 domainId, std::forward<AssembleElementFunc>(assembleElement)
546 );
547 return;
548 }
549 }
550
551 // fallback for coupling managers that don't support multithreaded assembly (yet)
552 // or if multithreaded assembly is disabled
553 // let the local assembler add the element contributions
554 for (const auto& element : elements(gridView(domainId)))
555 assembleElement(element);
556
557 // if we get here, everything worked well on this process
558 succeeded = true;
559 }
560 // throw exception if a problem occurred
561 catch (NumericalProblem &e)
562 {
563 std::cout << "rank " << gridView(domainId).comm().rank()
564 << " caught an exception while assembling:" << e.what()
565 << "\n";
566 succeeded = false;
567 }
568
569 // make sure everything worked well on all processes
570 if (gridView(domainId).comm().size() > 1)
571 succeeded = gridView(domainId).comm().min(succeeded);
572
573 // if not succeeded rethrow the error on all processes
574 if (!succeeded)
575 DUNE_THROW(NumericalProblem, "A process did not succeed in linearizing the system");
576 }
577
578 // get diagonal block pattern
579 template<std::size_t i, std::size_t j, typename std::enable_if_t<(i==j), int> = 0>
580 Dune::MatrixIndexSet getJacobianPattern_(Dune::index_constant<i> domainI,
581 Dune::index_constant<j> domainJ) const
582 {
583 const auto& gg = gridDiscretization(domainI);
584 auto pattern = getJacobianPattern<isImplicit()>(gg);
585 couplingManager_->extendJacobianPattern(domainI, pattern);
586 return pattern;
587 }
588
589 // get coupling block pattern
590 template<std::size_t i, std::size_t j, typename std::enable_if_t<(i!=j), int> = 0>
591 Dune::MatrixIndexSet getJacobianPattern_(Dune::index_constant<i> domainI,
592 Dune::index_constant<j> domainJ) const
593 {
595 domainI, gridDiscretization(domainI),
596 domainJ, gridDiscretization(domainJ));
597 }
598
599 // build periodic constraints into the system matrix
600 template<std::size_t i, class JacRow, class Res, class GG, class Sol>
601 void enforcePeriodicConstraints_(Dune::index_constant<i> domainI, JacRow& jacRow, Res& res, const GG& gridDiscretization, const Sol& curSol) const
602 {
604 {
605 for (const auto& m : gridDiscretization.periodicDofMap())
606 {
607 const auto& periodicallyMappedDofs = Dumux::Deprecated::ensureRangeOfPeriodicDofs(m.second);
608 if (std::ranges::all_of(periodicallyMappedDofs, [&](auto second){ return m.first < second; }))
609 {
610 for (const auto& second : periodicallyMappedDofs)
611 {
612 auto& jac = jacRow[domainI];
613
614 // add the second row to the first
615 res[m.first] += res[second];
616
617 const auto end = jac[second].end();
618 for (auto it = jac[second].begin(); it != end; ++it)
619 jac[m.first][it.index()] += (*it);
620
621
622 // enforce the solution of the first periodic DOF to the second one
623 res[second] = curSol[second] - curSol[m.first];
624
625 // set derivatives accordingly in jacobian, i.e. id for second and -id for m.first
626 auto setMatrixBlock = [] (auto& matrixBlock, double diagValue)
627 {
628 for (int eIdx = 0; eIdx < matrixBlock.N(); ++eIdx)
629 matrixBlock[eIdx][eIdx] = diagValue;
630 };
631
632 for (auto it = jac[second].begin(); it != end; ++it)
633 {
634 auto& matrixBlock = *it;
635 matrixBlock = 0.0;
636
637 assert(matrixBlock.N() == matrixBlock.M());
638 if(it.index() == second)
639 setMatrixBlock(matrixBlock, 1.0);
640
641 if(it.index() == m.first)
642 setMatrixBlock(matrixBlock, -1.0);
643
644 }
645
646 using namespace Dune::Hybrid;
647 forEach(makeIncompleteIntegerSequence<JacRow::size(), domainI>(), [&](const auto couplingDomainId)
648 {
649 auto& jacCoupling = jacRow[couplingDomainId];
650
651 for (auto it = jacCoupling[second].begin(); it != jacCoupling[second].end(); ++it)
652 jacCoupling[m.first][it.index()] += (*it);
653
654 for (auto it = jacCoupling[second].begin(); it != jacCoupling[second].end(); ++it)
655 (*it) = 0.0;
656 });
657 }
658 }
659 }
660 }
661 }
662
663 // enforce global constraints into the system matrix
664 template<std::size_t i, class JacRow, class Res, class GG, class Sol>
665 void enforceProblemConstraints_(Dune::index_constant<i> domainI, JacRow& jacRow, Res& res, const GG& gridDiscretization, const Sol& curSol) const
666 {
668 {
669 auto& jac = jacRow[domainI];
670 auto applyDirichletConstraint = [&] (const auto& dofIdx,
671 const auto& values,
672 const auto eqIdx,
673 const auto pvIdx)
674 {
675 (res)[dofIdx][eqIdx] = curSol[dofIdx][pvIdx] - values[pvIdx];
676
677 auto& row = jac[dofIdx];
678 for (auto col = row.begin(); col != row.end(); ++col)
679 row[col.index()][eqIdx] = 0.0;
680
681 jac[dofIdx][dofIdx][eqIdx][pvIdx] = 1.0;
682
683 using namespace Dune::Hybrid;
684 forEach(makeIncompleteIntegerSequence<JacRow::size(), domainI>(), [&](const auto couplingDomainId)
685 {
686 auto& jacCoupling = jacRow[couplingDomainId];
687
688 auto& rowCoupling = jacCoupling[dofIdx];
689 for (auto colCoupling = rowCoupling.begin(); colCoupling != rowCoupling.end(); ++colCoupling)
690 rowCoupling[colCoupling.index()][eqIdx] = 0.0;
691 });
692
693 };
694
695 for (const auto& constraintData : this->problem(domainI).constraints())
696 {
697 const auto& constraintInfo = constraintData.constraintInfo();
698 const auto& values = constraintData.values();
699 const auto dofIdx = constraintData.dofIndex();
700 // set the constraint in residual and jacobian
701 for (int eqIdx = 0; eqIdx < constraintInfo.size(); ++eqIdx)
702 {
703 if (constraintInfo.isConstraintEquation(eqIdx))
704 {
705 const auto pvIdx = constraintInfo.eqToPriVarIndex(eqIdx);
706 assert(0 <= pvIdx && pvIdx < constraintInfo.size());
707 applyDirichletConstraint(dofIdx, values, eqIdx, pvIdx);
708 }
709 }
710 }
711 }
712 }
713
714 // build periodic constraints in residual only
715 template<std::size_t i, class Res, class GG, class Sol>
716 void enforcePeriodicConstraints_(Dune::index_constant<i> domainI, Res& res, const GG& gridDiscretization, const Sol& curSol) const
717 {
719 {
720 for (const auto& m : gridDiscretization.periodicDofMap())
721 {
722 const auto& periodicallyMappedDofs = Dumux::Deprecated::ensureRangeOfPeriodicDofs(m.second);
723 if (std::ranges::all_of(periodicallyMappedDofs, [&](auto second){ return m.first < second; }))
724 {
725 for (const auto& second : periodicallyMappedDofs)
726 {
727 // add the second row to the first
728 res[m.first] += res[second];
729
730 // enforce the solution of the first periodic DOF to the second one
731 res[second] = curSol[second] - curSol[m.first];
732 }
733 }
734 }
735 }
736 }
737
738 // enforce global constraints in residual only
739 template<std::size_t i, class Res, class GG, class Sol>
740 void enforceProblemConstraints_(Dune::index_constant<i> domainI, Res& res, const GG& gridDiscretization, const Sol& curSol) const
741 {
743 {
744 for (const auto& constraintData : this->problem(domainI).constraints())
745 {
746 const auto& constraintInfo = constraintData.constraintInfo();
747 const auto& values = constraintData.values();
748 const auto dofIdx = constraintData.dofIndex();
749 for (int eqIdx = 0; eqIdx < constraintInfo.size(); ++eqIdx)
750 {
751 if (constraintInfo.isConstraintEquation(eqIdx))
752 {
753 const auto pvIdx = constraintInfo.eqToPriVarIndex(eqIdx);
754 assert(0 <= pvIdx && pvIdx < constraintInfo.size());
755 res[dofIdx][eqIdx] = curSol[dofIdx][pvIdx] - values[pvIdx];
756 }
757 }
758 }
759 }
760 }
761
763 ProblemTuple problemTuple_;
764
766 GridDiscretizationTuple gridDiscretizationTuple_;
767
769 GridVariablesTuple gridVariablesTuple_;
770
772 std::shared_ptr<const TimeLoop> timeLoop_;
773
775 const SolutionVector* prevSol_ = nullptr;
776
778 bool isStationaryProblem_;
779
781 std::shared_ptr<JacobianMatrix> jacobian_;
782 std::shared_ptr<ResidualType> residual_;
783
785 mutable bool warningIssued_;
786
788 bool enableMultithreading_ = false;
789};
790
791} // end namespace Dumux::Experimental
792
793#endif
Subdomain-specific views on multidomain assemblers.
Traits shared by the multi-domain assemblers.
The interface of the coupling manager for multi domain problems.
Definition multidomain/couplingmanager.hh:37
A linear system assembler (residual and Jacobian) for general schemes (FV, CVFE, FE,...
Definition multidomain/assembler.hh:66
typename MDTraits::ResidualVector ResidualType
Definition multidomain/assembler.hh:89
bool isStationaryProblem() const
Whether we are assembling a stationary or instationary problem.
Definition multidomain/assembler.hh:417
void setTimeLoop(std::shared_ptr< const TimeLoop > timeLoop)
Set time loop for instationary problems.
Definition multidomain/assembler.hh:399
typename MDTraits::template SubDomain< id >::GridVariables GridVariables
Definition multidomain/assembler.hh:79
void setJacobianBuildMode(JacobianMatrix &jac) const
Sets the jacobian build mode.
Definition multidomain/assembler.hh:303
LocalResidual< i > localResidual(Dune::index_constant< i > domainId) const
Create a local residual object (used by the local assembler).
Definition multidomain/assembler.hh:424
GetPropType< SubDomainTypeTag< id >, Properties::GridGeometry > GridDiscretization
Definition multidomain/assembler.hh:82
void updateGridVariables(const SolutionVector &curSol)
Updates the grid variables with the given solution.
Definition multidomain/assembler.hh:332
ResidualType & residual()
the full residual vector
Definition multidomain/assembler.hh:388
void updateAfterGridAdaption()
Resizes jacobian and residual and recomputes colors.
Definition multidomain/assembler.hh:322
void setLinearSystem(std::shared_ptr< JacobianMatrix > A, std::shared_ptr< ResidualType > r)
Tells the assembler which jacobian and residual to use. This also resizes the containers to the requi...
Definition multidomain/assembler.hh:275
const GridVariables< i > & gridVariables(Dune::index_constant< i > domainId) const
the grid variables of domain i
Definition multidomain/assembler.hh:376
std::size_t numDofs(Dune::index_constant< i > domainId) const
the number of dof locations of domain i
Definition multidomain/assembler.hh:351
void setTimeManager(std::shared_ptr< const TimeLoop > timeLoop)
Set time loop for instationary problems.
Definition multidomain/assembler.hh:404
const auto & gridView(Dune::index_constant< i > domainId) const
the grid view of domain i
Definition multidomain/assembler.hh:366
void assembleResidual(ResidualType &r, const SolutionVector &curSol)
assemble a residual r
Definition multidomain/assembler.hh:248
typename MDTraits::SolutionVector SolutionVector
Definition multidomain/assembler.hh:88
std::shared_ptr< CouplingManager > couplingManager_
Definition multidomain/assembler.hh:429
void setPreviousSolution(const SolutionVector &u)
Sets the solution from which to start the time integration. Has to be called prior to assembly for ti...
Definition multidomain/assembler.hh:411
JacobianMatrix & jacobian()
the full Jacobian matrix
Definition multidomain/assembler.hh:384
typename MDTraits::Scalar Scalar
Definition multidomain/assembler.hh:73
const auto & gridDiscretization(Dune::index_constant< i > domainId) const
Definition multidomain/assembler.hh:361
MDTraits Traits
Definition multidomain/assembler.hh:71
typename MDTraits::JacobianMatrix JacobianMatrix
Definition multidomain/assembler.hh:87
void setLinearSystem()
The version without arguments uses the default constructor to create the jacobian and residual object...
Definition multidomain/assembler.hh:290
GridVariables< i > & gridVariables(Dune::index_constant< i > domainId)
Definition multidomain/assembler.hh:371
static constexpr bool isImplicit()
Returns true if the assembler considers implicit assembly.
Definition multidomain/assembler.hh:96
const SolutionVector & prevSol() const
Definition multidomain/assembler.hh:392
typename MDTraits::template SubDomain< id >::LocalResidual LocalResidual
Definition multidomain/assembler.hh:76
MultiDomainAssembler(ProblemTuple problem, GridDiscretizationTuple gridDiscretization, GridVariablesTuple gridVariables, std::shared_ptr< CouplingManager > couplingManager)
The constructor for stationary problems.
Definition multidomain/assembler.hh:163
CMType CouplingManager
Definition multidomain/assembler.hh:91
void resetTimeStep(const SolutionVector &curSol)
Resets the grid variables to the last time step.
Definition multidomain/assembler.hh:342
const auto & problem(Dune::index_constant< i > domainId) const
Definition multidomain/assembler.hh:356
const CouplingManager & couplingManager() const
Definition multidomain/assembler.hh:380
void assembleResidual(const SolutionVector &curSol)
compute the residuals using the internal residual
Definition multidomain/assembler.hh:241
typename MDTraits::template SubDomain< id >::Problem Problem
Definition multidomain/assembler.hh:85
MultiDomainAssembler(ProblemTuple problem, GridDiscretizationTuple gridDiscretization, GridVariablesTuple gridVariables, std::shared_ptr< CouplingManager > couplingManager, std::shared_ptr< const TimeLoop > timeLoop, const SolutionVector &prevSol)
The constructor for instationary problems.
Definition multidomain/assembler.hh:191
void assembleJacobianAndResidual(const SolutionVector &curSol)
Assembles the global Jacobian of the residual and the residual for the current solution.
Definition multidomain/assembler.hh:220
The cell-centered scheme multidomain local assembler.
Definition experimental/assembly/subdomaincclocalassembler.hh:195
The CVFE scheme multidomain local assembler.
Definition experimental/assembly/subdomaincvfelocalassembler.hh:207
Subdomain-specific view on a multidomain assembler. Allows retrieval of sub-domain specific objects w...
Definition assemblerview.hh:33
The cell-centered scheme multidomain local assembler.
Definition multidomain/subdomaincclocalassembler.hh:270
The CVFE scheme multidomain local assembler.
Definition multidomain/subdomaincvfelocalassembler.hh:244
Manages the handling of time dependent problems.
Definition common/timeloop.hh:84
The default time loop for instationary simulations.
Definition common/timeloop.hh:139
Defines all properties used in Dumux.
Manages the handling of time dependent problems.
Helper function to generate Jacobian pattern for multi domain models.
Helpers for deprecation.
An enum class to define various differentiation methods available in order to compute the derivatives...
Some exceptions thrown in DuMux.
dune-grid capabilities compatibility layer
Dune::MatrixIndexSet getJacobianPattern(const GridGeometry &gridGeometry)
Helper function to generate Jacobian pattern for cell-centered methods.
Definition jacobianpattern.hh:29
Dune::MatrixIndexSet getCouplingJacobianPattern(const CouplingManager &couplingManager, Dune::index_constant< i > domainI, const GridGeometryI &gridGeometryI, Dune::index_constant< j > domainJ, const GridGeometryJ &gridGeometryJ)
Helper function to generate coupling Jacobian pattern (off-diagonal blocks) for cell-centered schemes...
Definition couplingjacobianpattern.hh:33
constexpr bool isSerial()
Checking whether the backend is serial.
Definition multithreading.hh:45
T getParam(Args &&... args)
A free function to get a parameter from the parameter tree singleton.
Definition parameters.hh:158
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition propertysystem.hh:296
Helper function to generate Jacobian pattern for different discretization methods.
The available discretization methods in Dumux.
A multidomain local assembler for Jacobian and residual contribution per element (cell-centered metho...
An assembler for Jacobian and residual contribution per element (CVFE methods) for multidomain proble...
Multithreading in Dumux.
Definition cellcentered/mpfa/elementvolumevariables.hh:24
constexpr bool hasPeriodicDofMap()
Definition periodic.hh:24
constexpr bool hasSubProblemGlobalConstraints()
Definition assemblytraits.hh:30
Definition method.hh:20
Definition assembly/assembler.hh:45
bool allGridsSupportsMultithreading(const std::tuple< GridDiscretizations... > &gridDiscretizations)
Whether the grid views of all grid discretizations support multithreading.
Definition gridcapabilities.hh:44
const Scalar PengRobinsonMixture< Scalar, StaticParameters >::u
Definition pengrobinsonmixture.hh:138
typename Detail::ConcatSeq< decltype(std::make_index_sequence< e >{}), e+1, decltype(std::make_index_sequence<(n > e) ?(n - e - 1) :0 >{})>::type makeIncompleteIntegerSequence
Definition utility.hh:58
Provides a helper class for nonoverlapping decomposition.
Type traits to detect periodicity support.
Type trait that is specialized for coupling manager supporting multithreaded assembly.
Definition assemblytraits.hh:43
An assembler for Jacobian and residual contribution per element (face-centered staggered methods) for...
Utilities for template meta programming.