version 3.8
nonlinear/newtonsolver.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-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_NEWTON_SOLVER_HH
13#define DUMUX_NEWTON_SOLVER_HH
14
15#include <cmath>
16#include <memory>
17#include <iostream>
18#include <type_traits>
19#include <algorithm>
20#include <numeric>
21
22#include <dune/common/timer.hh>
23#include <dune/common/exceptions.hh>
24#include <dune/common/parallel/mpicommunication.hh>
25#include <dune/common/parallel/mpihelper.hh>
26#include <dune/common/std/type_traits.hh>
27#include <dune/common/indices.hh>
28#include <dune/common/hybridutilities.hh>
29
30#include <dune/istl/bvector.hh>
31#include <dune/istl/multitypeblockvector.hh>
32
40
41#include <dumux/io/format.hh>
42
45
48
50
51// Helper boolean that states if the assembler exports grid variables
52template<class Assembler> using AssemblerGridVariablesType = typename Assembler::GridVariables;
53template<class Assembler>
54inline constexpr bool assemblerExportsGridVariables
55 = Dune::Std::is_detected_v<AssemblerGridVariablesType, Assembler>;
56
57// helper struct to define the variables on which the privarswitch should operate
58template<class Assembler, bool exportsGridVars = assemblerExportsGridVariables<Assembler>>
59struct PriVarSwitchVariablesType { using Type = typename Assembler::GridVariables; };
60
61// if assembler does not export them, use an empty class. These situations either mean
62// that there is no privarswitch, or, it is handled by a derived implementation.
63template<class Assembler>
64struct PriVarSwitchVariablesType<Assembler, false>
65{ using Type = struct EmptyGridVariables {}; };
66
67// Helper alias to deduce the variables types used in the privarswitch adapter
68template<class Assembler>
71
74{
75 template<class Assembler>
76 auto operator()(Assembler&& a)
77 -> decltype(a.assembleJacobianAndResidual(std::declval<const typename Assembler::SolutionVector&>(),
78 std::declval<const PartialReassembler<Assembler>*>()))
79 {}
80};
81
82// helpers to implement max relative shift
83template<class C> using dynamicIndexAccess = decltype(std::declval<C>()[0]);
84template<class C> using staticIndexAccess = decltype(std::declval<C>()[Dune::Indices::_0]);
85template<class C> static constexpr auto hasDynamicIndexAccess = Dune::Std::is_detected<dynamicIndexAccess, C>{};
86template<class C> static constexpr auto hasStaticIndexAccess = Dune::Std::is_detected<staticIndexAccess, C>{};
87
88template<class V, class Scalar, class Reduce, class Transform>
89auto hybridInnerProduct(const V& v1, const V& v2, Scalar init, Reduce&& r, Transform&& t)
90-> std::enable_if_t<hasDynamicIndexAccess<V>(), Scalar>
91{
92 return std::inner_product(v1.begin(), v1.end(), v2.begin(), init, std::forward<Reduce>(r), std::forward<Transform>(t));
93}
94
95template<class V, class Scalar, class Reduce, class Transform>
96auto hybridInnerProduct(const V& v1, const V& v2, Scalar init, Reduce&& r, Transform&& t)
97-> std::enable_if_t<hasStaticIndexAccess<V>() && !hasDynamicIndexAccess<V>(), Scalar>
98{
99 using namespace Dune::Hybrid;
100 forEach(std::make_index_sequence<V::N()>{}, [&](auto i){
101 init = r(init, hybridInnerProduct(v1[Dune::index_constant<i>{}], v2[Dune::index_constant<i>{}], init, std::forward<Reduce>(r), std::forward<Transform>(t)));
102 });
103 return init;
104}
105
106// Maximum relative shift at a degree of freedom.
107// For (primary variables) values below 1.0 we use
108// an absolute shift.
109template<class Scalar, class V>
110auto maxRelativeShift(const V& v1, const V& v2)
111-> std::enable_if_t<Dune::IsNumber<V>::value, Scalar>
112{
113 using std::abs; using std::max;
114 return abs(v1 - v2)/max<Scalar>(1.0, abs(v1 + v2)*0.5);
115}
116
117// Maximum relative shift for generic vector types.
118// Recursively calls maxRelativeShift until Dune::IsNumber is true.
119template<class Scalar, class V>
120auto maxRelativeShift(const V& v1, const V& v2)
121-> std::enable_if_t<!Dune::IsNumber<V>::value, Scalar>
122{
123 return hybridInnerProduct(v1, v2, Scalar(0.0),
124 [](const auto& a, const auto& b){ using std::max; return max(a, b); },
125 [](const auto& a, const auto& b){ return maxRelativeShift<Scalar>(a, b); }
126 );
127}
128
129template<class To, class From>
130void assign(To& to, const From& from)
131{
132 if constexpr (hasStaticIndexAccess<To>() && hasStaticIndexAccess<To>() && !hasDynamicIndexAccess<From>() && !hasDynamicIndexAccess<From>())
133 {
134 using namespace Dune::Hybrid;
135 forEach(std::make_index_sequence<To::N()>{}, [&](auto i){
136 assign(to[Dune::index_constant<i>{}], from[Dune::index_constant<i>{}]);
137 });
138 }
139
140 else if constexpr (std::is_assignable<To&, From>::value)
141 to = from;
142
143 else if constexpr (hasDynamicIndexAccess<To>() && hasDynamicIndexAccess<From>())
144 for (decltype(to.size()) i = 0; i < to.size(); ++i)
145 assign(to[i], from[i]);
146
147 else if constexpr (hasDynamicIndexAccess<To>() && Dune::IsNumber<From>::value)
148 {
149 assert(to.size() == 1);
150 assign(to[0], from);
151 }
152
153 else if constexpr (Dune::IsNumber<To>::value && hasDynamicIndexAccess<From>())
154 {
155 assert(from.size() == 1);
156 assign(to, from[0]);
157 }
158
159 else
160 DUNE_THROW(Dune::Exception, "Values are not assignable to each other!");
161}
162
163} // end namespace Dumux::Detail::Newton
164
165namespace Dumux {
166
177template <class Assembler, class LinearSolver,
178 class Reassembler = PartialReassembler<Assembler>,
179 class Comm = Dune::Communication<Dune::MPIHelper::MPICommunicator> >
180class NewtonSolver : public PDESolver<Assembler, LinearSolver>
181{
183
184protected:
186 using SolutionVector = typename Backend::DofVector;
187 using ResidualVector = typename Assembler::ResidualType;
189private:
190 using Scalar = typename Assembler::Scalar;
191 using JacobianMatrix = typename Assembler::JacobianMatrix;
194
195 // enable models with primary variable switch
196 // TODO: Always use ParentType::Variables once we require assemblers to export variables
197 static constexpr bool assemblerExportsVariables = Detail::PDESolver::assemblerExportsVariables<Assembler>;
198 using PriVarSwitchVariables
199 = std::conditional_t<assemblerExportsVariables,
200 typename ParentType::Variables,
203
204public:
205 using typename ParentType::Variables;
206 using Communication = Comm;
207
211 NewtonSolver(std::shared_ptr<Assembler> assembler,
212 std::shared_ptr<LinearSolver> linearSolver,
213 const Communication& comm = Dune::MPIHelper::getCommunication(),
214 const std::string& paramGroup = "")
216 , endIterMsgStream_(std::ostringstream::out)
217 , comm_(comm)
218 , paramGroup_(paramGroup)
219 , priVarSwitchAdapter_(std::make_unique<PrimaryVariableSwitchAdapter>(paramGroup))
220 {
221 initParams_(paramGroup);
222
223 // set the linear system (matrix & residual) in the assembler
224 this->assembler().setLinearSystem();
225
226 // set a different default for the linear solver residual reduction
227 // within the Newton the linear solver doesn't need to solve too exact
228 this->linearSolver().setResidualReduction(getParamFromGroup<Scalar>(paramGroup, "LinearSolver.ResidualReduction", 1e-6));
229
230 // initialize the partial reassembler
231 if (enablePartialReassembly_)
232 partialReassembler_ = std::make_unique<Reassembler>(this->assembler());
233 }
234
236 const Communication& comm() const
237 { return comm_; }
238
246 void setMaxRelativeShift(Scalar tolerance)
247 { shiftTolerance_ = tolerance; }
248
255 void setMaxAbsoluteResidual(Scalar tolerance)
256 { residualTolerance_ = tolerance; }
257
264 void setResidualReduction(Scalar tolerance)
265 { reductionTolerance_ = tolerance; }
266
277 void setTargetSteps(int targetSteps)
278 { targetSteps_ = targetSteps; }
279
286 void setMinSteps(int minSteps)
287 { minSteps_ = minSteps; }
288
295 void setMaxSteps(int maxSteps)
296 { maxSteps_ = maxSteps; }
297
305 void solve(Variables& vars, TimeLoop& timeLoop) override
306 {
307 if constexpr (!assemblerExportsVariables)
308 {
309 if (this->assembler().isStationaryProblem())
310 DUNE_THROW(Dune::InvalidStateException, "Using time step control with stationary problem makes no sense!");
311 }
312
313 // try solving the non-linear system
314 for (std::size_t i = 0; i <= maxTimeStepDivisions_; ++i)
315 {
316 // linearize & solve
317 const bool converged = solve_(vars);
318
319 if (converged)
320 return;
321
322 else if (!converged && i < maxTimeStepDivisions_)
323 {
324 if constexpr (assemblerExportsVariables)
325 DUNE_THROW(Dune::NotImplemented, "Time step reset for new assembly methods");
326 else
327 {
328 // set solution to previous solution & reset time step
329 Backend::update(vars, this->assembler().prevSol());
330 this->assembler().resetTimeStep(Backend::dofs(vars));
331
332 if (verbosity_ >= 1)
333 {
334 const auto dt = timeLoop.timeStepSize();
335 std::cout << Fmt::format("Newton solver did not converge with dt = {} seconds. ", dt)
336 << Fmt::format("Retrying with time step of dt = {} seconds.\n", dt*retryTimeStepReductionFactor_);
337 }
338
339 // try again with dt = dt * retryTimeStepReductionFactor_
340 timeLoop.setTimeStepSize(timeLoop.timeStepSize() * retryTimeStepReductionFactor_);
341 }
342 }
343
344 else
345 {
346 DUNE_THROW(NumericalProblem,
347 Fmt::format("Newton solver didn't converge after {} time-step divisions; dt = {}.\n",
348 maxTimeStepDivisions_, timeLoop.timeStepSize()));
349 }
350 }
351 }
352
359 void solve(Variables& vars) override
360 {
361 const bool converged = solve_(vars);
362 if (!converged)
363 DUNE_THROW(NumericalProblem,
364 Fmt::format("Newton solver didn't converge after {} iterations.\n", numSteps_));
365 }
366
375 bool apply(Variables& vars) override
376 {
377 return solve_(vars);
378 }
379
386 virtual void newtonBegin(Variables& initVars)
387 {
388 numSteps_ = 0;
389
390 if constexpr (hasPriVarsSwitch<PriVarSwitchVariables>)
391 {
392 if constexpr (assemblerExportsVariables)
393 priVarSwitchAdapter_->initialize(Backend::dofs(initVars), initVars);
394 else // this assumes assembly with solution (i.e. Variables=SolutionVector)
395 priVarSwitchAdapter_->initialize(initVars, this->assembler().gridVariables());
396 }
397
398
399 const auto& initSol = Backend::dofs(initVars);
400
401 // write the initial residual if a convergence writer was set
402 if (convergenceWriter_)
403 {
404 this->assembler().assembleResidual(initVars);
405
406 // dummy vector, there is no delta before solving the linear system
407 ResidualVector delta = LinearAlgebraNativeBackend::zeros(Backend::size(initSol));
408 convergenceWriter_->write(initSol, delta, this->assembler().residual());
409 }
410
411 if (enablePartialReassembly_)
412 {
413 partialReassembler_->resetColors();
414 resizeDistanceFromLastLinearization_(initSol, distanceFromLastLinearization_);
415 }
416 }
417
424 virtual bool newtonProceed(const Variables &varsCurrentIter, bool converged)
425 {
426 if (numSteps_ < minSteps_)
427 return true;
428 else if (converged)
429 return false; // we are below the desired tolerance
430 else if (numSteps_ >= maxSteps_)
431 {
432 // We have exceeded the allowed number of steps. If the
433 // maximum relative shift was reduced by a factor of at least 4,
434 // we proceed even if we are above the maximum number of steps.
435 if (enableShiftCriterion_)
436 return shift_*4.0 < lastShift_;
437 else
438 return reduction_*4.0 < lastReduction_;
439 }
440
441 return true;
442 }
443
447 virtual void newtonBeginStep(const Variables& vars)
448 {
450 if (numSteps_ == 0)
451 {
452 lastReduction_ = 1.0;
453 }
454 else
455 {
457 }
458 }
459
465 virtual void assembleLinearSystem(const Variables& vars)
466 {
467 assembleLinearSystem_(this->assembler(), vars);
468
469 if (enablePartialReassembly_)
470 partialReassembler_->report(comm_, endIterMsgStream_);
471 }
472
485 {
486 bool converged = false;
487
488 try
489 {
490 if (numSteps_ == 0)
491 initialResidual_ = this->linearSolver().norm(this->assembler().residual());
492
493 // solve by calling the appropriate implementation depending on whether the linear solver
494 // is capable of handling MultiType matrices or not
495 converged = solveLinearSystem_(deltaU);
496 }
497 catch (const Dune::Exception &e)
498 {
499 if (verbosity_ >= 1)
500 std::cout << "Newton: Caught exception from the linear solver: \"" << e.what() << "\"\n";
501
502 converged = false;
503 }
504
505 // make sure all processes converged
506 int convergedRemote = converged;
507 if (comm_.size() > 1)
508 convergedRemote = comm_.min(converged);
509
510 if (!converged)
511 {
512 DUNE_THROW(NumericalProblem, "Linear solver did not converge");
513 ++numLinearSolverBreakdowns_;
514 }
515 else if (!convergedRemote)
516 {
517 DUNE_THROW(NumericalProblem, "Linear solver did not converge on a remote process");
518 ++numLinearSolverBreakdowns_; // we keep correct count for process 0
519 }
520 }
521
540 const SolutionVector& uLastIter,
541 const ResidualVector& deltaU)
542 {
543 if (enableShiftCriterion_ || enablePartialReassembly_)
544 newtonUpdateShift_(uLastIter, deltaU);
545
546 if (enablePartialReassembly_) {
547 // Determine the threshold 'eps' that is used for the partial reassembly.
548 // Every entity where the primary variables exhibit a relative shift
549 // summed up since the last linearization above 'eps' will be colored
550 // red yielding a reassembly.
551 // The user can provide three parameters to influence the threshold:
552 // 'minEps' by 'Newton.ReassemblyMinThreshold' (1e-1*shiftTolerance_ default)
553 // 'maxEps' by 'Newton.ReassemblyMaxThreshold' (1e2*shiftTolerance_ default)
554 // 'omega' by 'Newton.ReassemblyShiftWeight' (1e-3 default)
555 // The threshold is calculated from the currently achieved maximum
556 // relative shift according to the formula
557 // eps = max( minEps, min(maxEps, omega*shift) ).
558 // Increasing/decreasing 'minEps' leads to less/more reassembly if
559 // 'omega*shift' is small, i.e., for the last Newton iterations.
560 // Increasing/decreasing 'maxEps' leads to less/more reassembly if
561 // 'omega*shift' is large, i.e., for the first Newton iterations.
562 // Increasing/decreasing 'omega' leads to more/less first and last
563 // iterations in this sense.
564 using std::max;
565 using std::min;
566 auto reassemblyThreshold = max(reassemblyMinThreshold_,
567 min(reassemblyMaxThreshold_,
568 shift_*reassemblyShiftWeight_));
569
570 updateDistanceFromLastLinearization_(uLastIter, deltaU);
571 partialReassembler_->computeColors(this->assembler(),
572 distanceFromLastLinearization_,
573 reassemblyThreshold);
574
575 // set the discrepancy of the red entities to zero
576 for (unsigned int i = 0; i < distanceFromLastLinearization_.size(); i++)
577 if (partialReassembler_->dofColor(i) == EntityColor::red)
578 distanceFromLastLinearization_[i] = 0;
579 }
580
581 if (useLineSearch_)
582 lineSearchUpdate_(vars, uLastIter, deltaU);
583
584 else if (useChop_)
585 choppedUpdate_(vars, uLastIter, deltaU);
586
587 else
588 {
589 auto uCurrentIter = uLastIter;
590 Backend::axpy(-1.0, deltaU, uCurrentIter);
591 solutionChanged_(vars, uCurrentIter);
592
593 if (enableResidualCriterion_)
595 }
596 }
597
604 virtual void newtonEndStep(Variables &vars,
605 const SolutionVector &uLastIter)
606 {
607 if constexpr (hasPriVarsSwitch<PriVarSwitchVariables>)
608 {
609 if constexpr (assemblerExportsVariables)
610 priVarSwitchAdapter_->invoke(Backend::dofs(vars), vars);
611 else // this assumes assembly with solution (i.e. Variables=SolutionVector)
612 priVarSwitchAdapter_->invoke(vars, this->assembler().gridVariables());
613 }
614
615 ++numSteps_;
616
617 if (verbosity_ >= 1)
618 {
619 if (enableDynamicOutput_)
620 std::cout << '\r'; // move cursor to beginning of line
621
622 const auto width = Fmt::formatted_size("{}", maxSteps_);
623 std::cout << Fmt::format("Newton iteration {:{}} done", numSteps_, width);
624
625 if (enableShiftCriterion_)
626 std::cout << Fmt::format(", maximum relative shift = {:.4e}", shift_);
627 if (enableResidualCriterion_ && enableAbsoluteResidualCriterion_)
628 std::cout << Fmt::format(", residual = {:.4e}", residualNorm_);
629 else if (enableResidualCriterion_)
630 std::cout << Fmt::format(", residual reduction = {:.4e}", reduction_);
631
632 std::cout << endIterMsgStream_.str() << "\n";
633 }
634 endIterMsgStream_.str("");
635
636 // When the Newton iterations are done: ask the model to check whether it makes sense
637 // TODO: how do we realize this? -> do this here in the Newton solver
638 // model_().checkPlausibility();
639 }
640
645 virtual void newtonEnd() {}
646
651 virtual bool newtonConverged() const
652 {
653 // in case the model has a priVar switch and some some primary variables
654 // actually switched their state in the last iteration, enforce another iteration
655 if (priVarSwitchAdapter_->switched())
656 return false;
657
658 if (enableShiftCriterion_ && !enableResidualCriterion_)
659 {
660 return shift_ <= shiftTolerance_;
661 }
662 else if (!enableShiftCriterion_ && enableResidualCriterion_)
663 {
664 if(enableAbsoluteResidualCriterion_)
665 return residualNorm_ <= residualTolerance_;
666 else
667 return reduction_ <= reductionTolerance_;
668 }
669 else if (satisfyResidualAndShiftCriterion_)
670 {
671 if(enableAbsoluteResidualCriterion_)
672 return shift_ <= shiftTolerance_
673 && residualNorm_ <= residualTolerance_;
674 else
675 return shift_ <= shiftTolerance_
676 && reduction_ <= reductionTolerance_;
677 }
678 else if(enableShiftCriterion_ && enableResidualCriterion_)
679 {
680 if(enableAbsoluteResidualCriterion_)
681 return shift_ <= shiftTolerance_
682 || residualNorm_ <= residualTolerance_;
683 else
684 return shift_ <= shiftTolerance_
685 || reduction_ <= reductionTolerance_;
686 }
687 else
688 {
689 return shift_ <= shiftTolerance_
690 || reduction_ <= reductionTolerance_
691 || residualNorm_ <= residualTolerance_;
692 }
693
694 return false;
695 }
696
701 virtual void newtonFail(Variables& u) {}
702
707 virtual void newtonSucceed() {}
708
712 void report(std::ostream& sout = std::cout) const
713 {
714 sout << '\n'
715 << "Newton statistics\n"
716 << "----------------------------------------------\n"
717 << "-- Total Newton iterations: " << totalWastedIter_ + totalSucceededIter_ << '\n'
718 << "-- Total wasted Newton iterations: " << totalWastedIter_ << '\n'
719 << "-- Total succeeded Newton iterations: " << totalSucceededIter_ << '\n'
720 << "-- Average iterations per solve: " << std::setprecision(3) << double(totalSucceededIter_) / double(numConverged_) << '\n'
721 << "-- Number of linear solver breakdowns: " << numLinearSolverBreakdowns_ << '\n'
722 << std::endl;
723 }
724
729 {
730 totalWastedIter_ = 0;
731 totalSucceededIter_ = 0;
732 numConverged_ = 0;
733 numLinearSolverBreakdowns_ = 0;
734 }
735
739 void reportParams(std::ostream& sout = std::cout) const
740 {
741 sout << "\nNewton solver configured with the following options and parameters:\n";
742 // options
743 if (useLineSearch_) sout << " -- Newton.UseLineSearch = true\n";
744 if (useChop_) sout << " -- Newton.EnableChop = true\n";
745 if (enablePartialReassembly_) sout << " -- Newton.EnablePartialReassembly = true\n";
746 if (enableAbsoluteResidualCriterion_) sout << " -- Newton.EnableAbsoluteResidualCriterion = true\n";
747 if (enableShiftCriterion_) sout << " -- Newton.EnableShiftCriterion = true (relative shift convergence criterion)\n";
748 if (enableResidualCriterion_) sout << " -- Newton.EnableResidualCriterion = true\n";
749 if (satisfyResidualAndShiftCriterion_) sout << " -- Newton.SatisfyResidualAndShiftCriterion = true\n";
750 // parameters
751 if (enableShiftCriterion_) sout << " -- Newton.MaxRelativeShift = " << shiftTolerance_ << '\n';
752 if (enableAbsoluteResidualCriterion_) sout << " -- Newton.MaxAbsoluteResidual = " << residualTolerance_ << '\n';
753 if (enableResidualCriterion_) sout << " -- Newton.ResidualReduction = " << reductionTolerance_ << '\n';
754 sout << " -- Newton.MinSteps = " << minSteps_ << '\n';
755 sout << " -- Newton.MaxSteps = " << maxSteps_ << '\n';
756 sout << " -- Newton.TargetSteps = " << targetSteps_ << '\n';
757 if (enablePartialReassembly_)
758 {
759 sout << " -- Newton.ReassemblyMinThreshold = " << reassemblyMinThreshold_ << '\n';
760 sout << " -- Newton.ReassemblyMaxThreshold = " << reassemblyMaxThreshold_ << '\n';
761 sout << " -- Newton.ReassemblyShiftWeight = " << reassemblyShiftWeight_ << '\n';
762 }
763 sout << " -- Newton.RetryTimeStepReductionFactor = " << retryTimeStepReductionFactor_ << '\n';
764 sout << " -- Newton.MaxTimeStepDivisions = " << maxTimeStepDivisions_ << '\n';
765 sout << std::endl;
766 }
767
776 Scalar suggestTimeStepSize(Scalar oldTimeStep) const
777 {
778 // be aggressive reducing the time-step size but
779 // conservative when increasing it. the rationale is
780 // that we want to avoid failing in the next Newton
781 // iteration which would require another linearization
782 // of the problem.
783 if (numSteps_ > targetSteps_) {
784 Scalar percent = Scalar(numSteps_ - targetSteps_)/targetSteps_;
785 return oldTimeStep/(1.0 + percent);
786 }
787
788 Scalar percent = Scalar(targetSteps_ - numSteps_)/targetSteps_;
789 return oldTimeStep*(1.0 + percent/1.2);
790 }
791
795 void setVerbosity(int val)
796 { verbosity_ = val; }
797
801 int verbosity() const
802 { return verbosity_ ; }
803
807 const std::string& paramGroup() const
808 { return paramGroup_; }
809
813 void attachConvergenceWriter(std::shared_ptr<ConvergenceWriter> convWriter)
814 { convergenceWriter_ = convWriter; }
815
820 { convergenceWriter_ = nullptr; }
821
826 { return retryTimeStepReductionFactor_; }
827
831 void setRetryTimeStepReductionFactor(const Scalar factor)
832 { retryTimeStepReductionFactor_ = factor; }
833
834protected:
835
841 virtual void solutionChanged_(Variables& vars, const SolutionVector& uCurrentIter)
842 {
843 Backend::update(vars, uCurrentIter);
844
845 if constexpr (!assemblerExportsVariables)
846 this->assembler().updateGridVariables(Backend::dofs(vars));
847 }
848
850 {
851 // we assume that the assembler works on solution vectors
852 // if it doesn't export the variables type
853 if constexpr (!assemblerExportsVariables)
854 this->assembler().assembleResidual(Backend::dofs(vars));
855 else
856 this->assembler().assembleResidual(vars);
857
858 residualNorm_ = this->linearSolver().norm(this->assembler().residual());
859
861 }
862
864 { return enableResidualCriterion_; }
865
874
875 // residual criterion variables
880
881 // shift criterion variables
882 Scalar shift_;
884
886 std::ostringstream endIterMsgStream_;
887
888
889private:
890
895 bool solve_(Variables& vars)
896 {
897 try
898 {
899 // newtonBegin may manipulate the solution
900 newtonBegin(vars);
901
902 // the given solution is the initial guess
903 auto uLastIter = Backend::dofs(vars);
904 ResidualVector deltaU = LinearAlgebraNativeBackend::zeros(Backend::size(Backend::dofs(vars)));
905 Detail::Newton::assign(deltaU, Backend::dofs(vars));
906
907 // setup timers
908 Dune::Timer assembleTimer(false);
909 Dune::Timer solveTimer(false);
910 Dune::Timer updateTimer(false);
911
912 // execute the method as long as the solver thinks
913 // that we should do another iteration
914 bool converged = false;
915 while (newtonProceed(vars, converged))
916 {
917 // notify the solver that we're about to start
918 // a new iteration
919 newtonBeginStep(vars);
920
921 // make the current solution to the old one
922 if (numSteps_ > 0)
923 uLastIter = Backend::dofs(vars);
924
925 if (verbosity_ >= 1 && enableDynamicOutput_)
926 std::cout << "Assemble: r(x^k) = dS/dt + div F - q; M = grad r"
927 << std::flush;
928
930 // assemble
932
933 // linearize the problem at the current solution
934 assembleTimer.start();
936 assembleTimer.stop();
937
939 // linear solve
941
942 // Clear the current line using an ansi escape
943 // sequence. for an explanation see
944 // http://en.wikipedia.org/wiki/ANSI_escape_code
945 const char clearRemainingLine[] = { 0x1b, '[', 'K', 0 };
946
947 if (verbosity_ >= 1 && enableDynamicOutput_)
948 std::cout << "\rSolve: M deltax^k = r"
949 << clearRemainingLine << std::flush;
950
951 // solve the resulting linear equation system
952 solveTimer.start();
953
954 // set the delta vector to zero before solving the linear system!
955 deltaU = 0;
956
957 solveLinearSystem(deltaU);
958 solveTimer.stop();
959
961 // update
963 if (verbosity_ >= 1 && enableDynamicOutput_)
964 std::cout << "\rUpdate: x^(k+1) = x^k - deltax^k"
965 << clearRemainingLine << std::flush;
966
967 updateTimer.start();
968 // update the current solution (i.e. uOld) with the delta
969 // (i.e. u). The result is stored in u
970 newtonUpdate(vars, uLastIter, deltaU);
971 updateTimer.stop();
972
973 // tell the solver that we're done with this iteration
974 newtonEndStep(vars, uLastIter);
975
976 // if a convergence writer was specified compute residual and write output
977 if (convergenceWriter_)
978 {
979 this->assembler().assembleResidual(vars);
980 convergenceWriter_->write(Backend::dofs(vars), deltaU, this->assembler().residual());
981 }
982
983 // detect if the method has converged
984 converged = newtonConverged();
985 }
986
987 // tell solver we are done
988 newtonEnd();
989
990 // reset state if Newton failed
991 if (!newtonConverged())
992 {
993 totalWastedIter_ += numSteps_;
994 newtonFail(vars);
995 return false;
996 }
997
998 totalSucceededIter_ += numSteps_;
999 numConverged_++;
1000
1001 // tell solver we converged successfully
1002 newtonSucceed();
1003
1004 if (verbosity_ >= 1) {
1005 const auto elapsedTot = assembleTimer.elapsed() + solveTimer.elapsed() + updateTimer.elapsed();
1006 std::cout << Fmt::format("Assemble/solve/update time: {:.2g}({:.2f}%)/{:.2g}({:.2f}%)/{:.2g}({:.2f}%)\n",
1007 assembleTimer.elapsed(), 100*assembleTimer.elapsed()/elapsedTot,
1008 solveTimer.elapsed(), 100*solveTimer.elapsed()/elapsedTot,
1009 updateTimer.elapsed(), 100*updateTimer.elapsed()/elapsedTot);
1010 }
1011 return true;
1012
1013 }
1014 catch (const NumericalProblem &e)
1015 {
1016 if (verbosity_ >= 1)
1017 std::cout << "Newton: Caught exception: \"" << e.what() << "\"\n";
1018
1019 totalWastedIter_ += numSteps_;
1020
1021 newtonFail(vars);
1022 return false;
1023 }
1024 }
1025
1027 template<class A>
1028 auto assembleLinearSystem_(const A& assembler, const Variables& vars)
1029 -> typename std::enable_if_t<decltype(isValid(Detail::Newton::supportsPartialReassembly())(assembler))::value, void>
1030 {
1031 this->assembler().assembleJacobianAndResidual(vars, partialReassembler_.get());
1032 }
1033
1035 template<class A>
1036 auto assembleLinearSystem_(const A& assembler, const Variables& vars)
1037 -> typename std::enable_if_t<!decltype(isValid(Detail::Newton::supportsPartialReassembly())(assembler))::value, void>
1038 {
1039 this->assembler().assembleJacobianAndResidual(vars);
1040 }
1041
1049 virtual void newtonUpdateShift_(const SolutionVector &uLastIter,
1050 const ResidualVector &deltaU)
1051 {
1052 auto uNew = uLastIter;
1053 Backend::axpy(-1.0, deltaU, uNew);
1054 shift_ = Detail::Newton::maxRelativeShift<Scalar>(uLastIter, uNew);
1055
1056 if (comm_.size() > 1)
1057 shift_ = comm_.max(shift_);
1058 }
1059
1060 virtual void lineSearchUpdate_(Variables &vars,
1061 const SolutionVector &uLastIter,
1062 const ResidualVector &deltaU)
1063 {
1064 Scalar lambda = 1.0;
1065 auto uCurrentIter = uLastIter;
1066
1067 while (true)
1068 {
1069 Backend::axpy(-lambda, deltaU, uCurrentIter);
1070 solutionChanged_(vars, uCurrentIter);
1071
1072 computeResidualReduction_(vars);
1073
1074 if (reduction_ < lastReduction_ || lambda <= lineSearchMinRelaxationFactor_)
1075 {
1076 endIterMsgStream_ << Fmt::format(", residual reduction {:.4e}->{:.4e}@lambda={:.4f}", lastReduction_, reduction_, lambda);
1077 return;
1078 }
1079
1080 // try with a smaller update and reset solution
1081 lambda *= 0.5;
1082 uCurrentIter = uLastIter;
1083 }
1084 }
1085
1087 virtual void choppedUpdate_(Variables& vars,
1088 const SolutionVector& uLastIter,
1089 const ResidualVector& deltaU)
1090 {
1091 DUNE_THROW(Dune::NotImplemented,
1092 "Chopped Newton update strategy not implemented.");
1093 }
1094
1100 virtual bool solveLinearSystem_(ResidualVector& deltaU)
1101 {
1102 assert(this->checkSizesOfSubMatrices(this->assembler().jacobian()) && "Matrix blocks have wrong sizes!");
1103
1104 return this->linearSolver().solve(
1105 this->assembler().jacobian(),
1106 deltaU,
1107 this->assembler().residual()
1108 );
1109 }
1110
1112 void initParams_(const std::string& group = "")
1113 {
1114 useLineSearch_ = getParamFromGroup<bool>(group, "Newton.UseLineSearch", false);
1115 lineSearchMinRelaxationFactor_ = getParamFromGroup<Scalar>(group, "Newton.LineSearchMinRelaxationFactor", 0.125);
1116 useChop_ = getParamFromGroup<bool>(group, "Newton.EnableChop", false);
1117 if(useLineSearch_ && useChop_)
1118 DUNE_THROW(Dune::InvalidStateException, "Use either linesearch OR chop!");
1119
1120 enableAbsoluteResidualCriterion_ = getParamFromGroup<bool>(group, "Newton.EnableAbsoluteResidualCriterion", false);
1121 enableShiftCriterion_ = getParamFromGroup<bool>(group, "Newton.EnableShiftCriterion", true);
1122 enableResidualCriterion_ = getParamFromGroup<bool>(group, "Newton.EnableResidualCriterion", false) || enableAbsoluteResidualCriterion_;
1123 satisfyResidualAndShiftCriterion_ = getParamFromGroup<bool>(group, "Newton.SatisfyResidualAndShiftCriterion", false);
1124 enableDynamicOutput_ = getParamFromGroup<bool>(group, "Newton.EnableDynamicOutput", true);
1125
1126 if (!enableShiftCriterion_ && !enableResidualCriterion_)
1127 {
1128 DUNE_THROW(Dune::NotImplemented,
1129 "at least one of NewtonEnableShiftCriterion or "
1130 << "NewtonEnableResidualCriterion has to be set to true");
1131 }
1132
1133 setMaxRelativeShift(getParamFromGroup<Scalar>(group, "Newton.MaxRelativeShift", 1e-8));
1134 setMaxAbsoluteResidual(getParamFromGroup<Scalar>(group, "Newton.MaxAbsoluteResidual", 1e-5));
1135 setResidualReduction(getParamFromGroup<Scalar>(group, "Newton.ResidualReduction", 1e-5));
1136 setTargetSteps(getParamFromGroup<int>(group, "Newton.TargetSteps", 10));
1137 setMinSteps(getParamFromGroup<int>(group, "Newton.MinSteps", 2));
1138 setMaxSteps(getParamFromGroup<int>(group, "Newton.MaxSteps", 18));
1139
1140 enablePartialReassembly_ = getParamFromGroup<bool>(group, "Newton.EnablePartialReassembly", false);
1141 reassemblyMinThreshold_ = getParamFromGroup<Scalar>(group, "Newton.ReassemblyMinThreshold", 1e-1*shiftTolerance_);
1142 reassemblyMaxThreshold_ = getParamFromGroup<Scalar>(group, "Newton.ReassemblyMaxThreshold", 1e2*shiftTolerance_);
1143 reassemblyShiftWeight_ = getParamFromGroup<Scalar>(group, "Newton.ReassemblyShiftWeight", 1e-3);
1144
1145 maxTimeStepDivisions_ = getParamFromGroup<std::size_t>(group, "Newton.MaxTimeStepDivisions", 10);
1146 retryTimeStepReductionFactor_ = getParamFromGroup<Scalar>(group, "Newton.RetryTimeStepReductionFactor", 0.5);
1147
1148 verbosity_ = comm_.rank() == 0 ? getParamFromGroup<int>(group, "Newton.Verbosity", 2) : 0;
1149 numSteps_ = 0;
1150
1151 // output a parameter report
1152 if (verbosity_ >= 2)
1153 reportParams();
1154 }
1155
1156 template<class SolA, class SolB>
1157 void updateDistanceFromLastLinearization_(const SolA& u, const SolB& uDelta)
1158 {
1159 if constexpr (Dune::IsNumber<SolA>::value)
1160 {
1161 auto nextPriVars = u;
1162 nextPriVars -= uDelta;
1163
1164 // add the current relative shift for this degree of freedom
1165 auto shift = Detail::Newton::maxRelativeShift<Scalar>(u, nextPriVars);
1166 distanceFromLastLinearization_[0] += shift;
1167 }
1168 else
1169 {
1170 for (std::size_t i = 0; i < u.size(); ++i)
1171 {
1172 const auto& currentPriVars(u[i]);
1173 auto nextPriVars(currentPriVars);
1174 nextPriVars -= uDelta[i];
1175
1176 // add the current relative shift for this degree of freedom
1177 auto shift = Detail::Newton::maxRelativeShift<Scalar>(currentPriVars, nextPriVars);
1178 distanceFromLastLinearization_[i] += shift;
1179 }
1180 }
1181 }
1182
1183 template<class ...ArgsA, class...ArgsB>
1184 void updateDistanceFromLastLinearization_(const Dune::MultiTypeBlockVector<ArgsA...>& uLastIter,
1186 {
1187 DUNE_THROW(Dune::NotImplemented, "Reassembly for MultiTypeBlockVector");
1188 }
1189
1190 template<class Sol>
1191 void resizeDistanceFromLastLinearization_(const Sol& u, std::vector<Scalar>& dist)
1192 {
1193 dist.assign(Backend::size(u), 0.0);
1194 }
1195
1196 template<class ...Args>
1197 void resizeDistanceFromLastLinearization_(const Dune::MultiTypeBlockVector<Args...>& u,
1198 std::vector<Scalar>& dist)
1199 {
1200 DUNE_THROW(Dune::NotImplemented, "Reassembly for MultiTypeBlockVector");
1201 }
1202
1204 Communication comm_;
1205
1207 int verbosity_;
1208
1209 Scalar shiftTolerance_;
1210 Scalar reductionTolerance_;
1211 Scalar residualTolerance_;
1212
1213 // time step control
1214 std::size_t maxTimeStepDivisions_;
1215 Scalar retryTimeStepReductionFactor_;
1216
1217 // further parameters
1218 bool useLineSearch_;
1219 Scalar lineSearchMinRelaxationFactor_;
1220 bool useChop_;
1221 bool enableAbsoluteResidualCriterion_;
1222 bool enableShiftCriterion_;
1223 bool enableResidualCriterion_;
1224 bool satisfyResidualAndShiftCriterion_;
1225 bool enableDynamicOutput_;
1226
1228 std::string paramGroup_;
1229
1230 // infrastructure for partial reassembly
1231 bool enablePartialReassembly_;
1232 std::unique_ptr<Reassembler> partialReassembler_;
1233 std::vector<Scalar> distanceFromLastLinearization_;
1234 Scalar reassemblyMinThreshold_;
1235 Scalar reassemblyMaxThreshold_;
1236 Scalar reassemblyShiftWeight_;
1237
1238 // statistics for the optional report
1239 std::size_t totalWastedIter_ = 0;
1240 std::size_t totalSucceededIter_ = 0;
1241 std::size_t numConverged_ = 0;
1242 std::size_t numLinearSolverBreakdowns_ = 0;
1243
1245 std::unique_ptr<PrimaryVariableSwitchAdapter> priVarSwitchAdapter_;
1246
1248 std::shared_ptr<ConvergenceWriter> convergenceWriter_ = nullptr;
1249};
1250
1251} // end namespace Dumux
1252
1253#endif
Definition: variablesbackend.hh:159
Base class for linear solvers.
Definition: solver.hh:27
An implementation of a Newton solver.
Definition: nonlinear/newtonsolver.hh:181
Comm Communication
Definition: nonlinear/newtonsolver.hh:206
virtual void newtonFail(Variables &u)
Called if the Newton method broke down. This method is called after newtonEnd()
Definition: nonlinear/newtonsolver.hh:701
int maxSteps_
maximum number of iterations we do before giving up
Definition: nonlinear/newtonsolver.hh:871
void setMaxSteps(int maxSteps)
Set the number of iterations after which the Newton method gives up.
Definition: nonlinear/newtonsolver.hh:295
typename Assembler::ResidualType ResidualVector
Definition: nonlinear/newtonsolver.hh:187
void solveLinearSystem(ResidualVector &deltaU)
Solve the linear system of equations .
Definition: nonlinear/newtonsolver.hh:484
void setResidualReduction(Scalar tolerance)
Set the maximum acceptable residual norm reduction.
Definition: nonlinear/newtonsolver.hh:264
void reportParams(std::ostream &sout=std::cout) const
Report the options and parameters this Newton is configured with.
Definition: nonlinear/newtonsolver.hh:739
int targetSteps_
optimal number of iterations we want to achieve
Definition: nonlinear/newtonsolver.hh:867
const std::string & paramGroup() const
Returns the parameter group.
Definition: nonlinear/newtonsolver.hh:807
void setRetryTimeStepReductionFactor(const Scalar factor)
Set the factor for reducing the time step after a Newton iteration has failed.
Definition: nonlinear/newtonsolver.hh:831
Scalar reduction_
Definition: nonlinear/newtonsolver.hh:876
Scalar retryTimeStepReductionFactor() const
Return the factor for reducing the time step after a Newton iteration has failed.
Definition: nonlinear/newtonsolver.hh:825
int numSteps_
actual number of steps done so far
Definition: nonlinear/newtonsolver.hh:873
int verbosity() const
Return the verbosity level.
Definition: nonlinear/newtonsolver.hh:801
void setMinSteps(int minSteps)
Set the number of minimum iterations for the Newton method.
Definition: nonlinear/newtonsolver.hh:286
void newtonUpdate(Variables &vars, const SolutionVector &uLastIter, const ResidualVector &deltaU)
Update the current solution with a delta vector.
Definition: nonlinear/newtonsolver.hh:539
int minSteps_
minimum number of iterations we do
Definition: nonlinear/newtonsolver.hh:869
virtual void newtonBegin(Variables &initVars)
Called before the Newton method is applied to an non-linear system of equations.
Definition: nonlinear/newtonsolver.hh:386
virtual void assembleLinearSystem(const Variables &vars)
Assemble the linear system of equations .
Definition: nonlinear/newtonsolver.hh:465
bool enableResidualCriterion() const
Definition: nonlinear/newtonsolver.hh:863
virtual bool newtonProceed(const Variables &varsCurrentIter, bool converged)
Returns true if another iteration should be done.
Definition: nonlinear/newtonsolver.hh:424
void solve(Variables &vars, TimeLoop &timeLoop) override
Run the Newton method to solve a non-linear system. Does time step control when the Newton fails to c...
Definition: nonlinear/newtonsolver.hh:305
virtual void newtonEndStep(Variables &vars, const SolutionVector &uLastIter)
Indicates that one Newton iteration was finished.
Definition: nonlinear/newtonsolver.hh:604
virtual void solutionChanged_(Variables &vars, const SolutionVector &uCurrentIter)
Update solution-dependent quantities like grid variables after the solution has changed.
Definition: nonlinear/newtonsolver.hh:841
void report(std::ostream &sout=std::cout) const
output statistics / report
Definition: nonlinear/newtonsolver.hh:712
void solve(Variables &vars) override
Run the Newton method to solve a non-linear system. The solver is responsible for all the strategic d...
Definition: nonlinear/newtonsolver.hh:359
bool apply(Variables &vars) override
Run the Newton method to solve a non-linear system. The solver is responsible for all the strategic d...
Definition: nonlinear/newtonsolver.hh:375
virtual void newtonSucceed()
Called if the Newton method ended successfully This method is called after newtonEnd()
Definition: nonlinear/newtonsolver.hh:707
void attachConvergenceWriter(std::shared_ptr< ConvergenceWriter > convWriter)
Attach a convergence writer to write out intermediate results after each iteration.
Definition: nonlinear/newtonsolver.hh:813
Scalar initialResidual_
Definition: nonlinear/newtonsolver.hh:879
Scalar lastReduction_
Definition: nonlinear/newtonsolver.hh:878
virtual void newtonBeginStep(const Variables &vars)
Indicates the beginning of a Newton iteration.
Definition: nonlinear/newtonsolver.hh:447
std::ostringstream endIterMsgStream_
message stream to be displayed at the end of iterations
Definition: nonlinear/newtonsolver.hh:886
void setVerbosity(int val)
Specifies the verbosity level.
Definition: nonlinear/newtonsolver.hh:795
typename Backend::DofVector SolutionVector
Definition: nonlinear/newtonsolver.hh:186
const Communication & comm() const
the communicator for parallel runs
Definition: nonlinear/newtonsolver.hh:236
void resetReport()
reset the statistics
Definition: nonlinear/newtonsolver.hh:728
NewtonSolver(std::shared_ptr< Assembler > assembler, std::shared_ptr< LinearSolver > linearSolver, const Communication &comm=Dune::MPIHelper::getCommunication(), const std::string &paramGroup="")
The Constructor.
Definition: nonlinear/newtonsolver.hh:211
void setMaxAbsoluteResidual(Scalar tolerance)
Set the maximum acceptable absolute residual for declaring convergence.
Definition: nonlinear/newtonsolver.hh:255
virtual void newtonEnd()
Called if the Newton method ended (not known yet if we failed or succeeded)
Definition: nonlinear/newtonsolver.hh:645
void setTargetSteps(int targetSteps)
Set the number of iterations at which the Newton method should aim at.
Definition: nonlinear/newtonsolver.hh:277
virtual bool newtonConverged() const
Returns true if the error of the solution is below the tolerance.
Definition: nonlinear/newtonsolver.hh:651
Scalar suggestTimeStepSize(Scalar oldTimeStep) const
Suggest a new time-step size based on the old time-step size.
Definition: nonlinear/newtonsolver.hh:776
void detachConvergenceWriter()
Detach the convergence writer to stop the output.
Definition: nonlinear/newtonsolver.hh:819
void setMaxRelativeShift(Scalar tolerance)
Set the maximum acceptable difference of any primary variable between two iterations for declaring co...
Definition: nonlinear/newtonsolver.hh:246
Scalar shift_
Definition: nonlinear/newtonsolver.hh:882
void computeResidualReduction_(const Variables &vars)
Definition: nonlinear/newtonsolver.hh:849
Scalar residualNorm_
Definition: nonlinear/newtonsolver.hh:877
Scalar lastShift_
Definition: nonlinear/newtonsolver.hh:883
Exception thrown if a fixable numerical problem occurs.
Definition: exceptions.hh:27
A high-level interface for a PDESolver.
Definition: common/pdesolver.hh:61
const LinearSolver & linearSolver() const
Access the linear solver.
Definition: common/pdesolver.hh:133
const Assembler & assembler() const
Access the assembler.
Definition: common/pdesolver.hh:121
Detail::PDESolver::AssemblerVariables< Assembler > Variables
export the type of variables that represent a numerical solution
Definition: common/pdesolver.hh:71
detects which entries in the Jacobian have to be recomputed
Definition: partialreassembler.hh:420
An adapter for the Newton to manage models with primary variable switch.
Definition: primaryvariableswitchadapter.hh:44
virtual void setTimeStepSize(Scalar dt)=0
Set the current time step size to a given value.
virtual Scalar timeStepSize() const =0
Returns the suggested time step length .
Definition: variablesbackend.hh:31
Defines a high-level interface for a PDESolver.
Manages the handling of time dependent problems.
Some exceptions thrown in DuMux
Formatting based on the fmt-library which implements std::format of C++20.
@ red
distance from last linearization is above the tolerance
constexpr auto isValid(const Expression &t)
A function that creates a test functor to do class member introspection at compile time.
Definition: isvalid.hh:81
A helper function for class member function introspection.
A helper class that converts a Dune::MultiTypeBlockMatrix into a plain Dune::BCRSMatrix.
Definition: nonlinear/newtonsolver.hh:49
static constexpr auto hasStaticIndexAccess
Definition: nonlinear/newtonsolver.hh:86
auto maxRelativeShift(const V &v1, const V &v2) -> std::enable_if_t< Dune::IsNumber< V >::value, Scalar >
Definition: nonlinear/newtonsolver.hh:110
void assign(To &to, const From &from)
Definition: nonlinear/newtonsolver.hh:130
decltype(std::declval< C >()[0]) dynamicIndexAccess
Definition: nonlinear/newtonsolver.hh:83
auto hybridInnerProduct(const V &v1, const V &v2, Scalar init, Reduce &&r, Transform &&t) -> std::enable_if_t< hasDynamicIndexAccess< V >(), Scalar >
Definition: nonlinear/newtonsolver.hh:89
decltype(std::declval< C >()[Dune::Indices::_0]) staticIndexAccess
Definition: nonlinear/newtonsolver.hh:84
typename Assembler::GridVariables AssemblerGridVariablesType
Definition: nonlinear/newtonsolver.hh:52
static constexpr auto hasDynamicIndexAccess
Definition: nonlinear/newtonsolver.hh:85
typename PriVarSwitchVariablesType< Assembler, assemblerExportsGridVariables< Assembler > >::Type PriVarSwitchVariables
Definition: nonlinear/newtonsolver.hh:70
constexpr bool assemblerExportsGridVariables
Definition: nonlinear/newtonsolver.hh:55
Definition: adapt.hh:17
This class provides the infrastructure to write the convergence behaviour of the newton method into a...
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
Detects which entries in the Jacobian have to be recomputed.
An adapter for the Newton to manage models with primary variable switch.
Definition: nonlinear/newtonconvergencewriter.hh:27
EmptyGridVariables {} Type
Definition: nonlinear/newtonsolver.hh:65
Definition: nonlinear/newtonsolver.hh:59
typename Assembler::GridVariables Type
Definition: nonlinear/newtonsolver.hh:59
helper struct detecting if an assembler supports partial reassembly
Definition: nonlinear/newtonsolver.hh:74
auto operator()(Assembler &&a) -> decltype(a.assembleJacobianAndResidual(std::declval< const typename Assembler::SolutionVector & >(), std::declval< const PartialReassembler< Assembler > * >()))
Definition: nonlinear/newtonsolver.hh:76
Backends for operations on different solution vector types or more generic variable classes to be use...
Type traits to be used with vector types.