Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #pragma once 11 : 12 : #include "SystemBase.h" 13 : #include "MooseTypes.h" 14 : 15 : #include "libmesh/system.h" 16 : 17 : #include <string> 18 : 19 : class SubProblem; 20 : class FEProblemBase; 21 : 22 : namespace SparsityPattern = libMesh::SparsityPattern; 23 : 24 : class SolverSystem : public SystemBase 25 : { 26 : public: 27 : SolverSystem(SubProblem & subproblem, 28 : FEProblemBase & fe_problem, 29 : const std::string & name, 30 : Moose::VarKindType var_kind); 31 : virtual ~SolverSystem(); 32 : 33 : virtual void preInit() override; 34 : virtual void restoreSolutions() override final; 35 : 36 : void serializeSolution(); 37 : 38 : /** 39 : * Quit the current solve as soon as possible. 40 : */ 41 : virtual void stopSolve(const ExecFlagType & exec_flag, 42 : const std::set<TagID> & vector_tags_to_close) = 0; 43 : 44 : /** 45 : * Returns the convergence state 46 : * @return true if converged, otherwise false 47 : */ 48 : virtual bool converged() = 0; 49 : 50 : /** 51 : * If the system has a kernel that corresponds to a time derivative 52 : */ 53 : virtual bool containsTimeKernel() = 0; 54 : 55 : /** 56 : * Returns the names of the variables that have time derivative kernels 57 : * in the system. 58 : */ 59 : virtual std::vector<std::string> timeKernelVariableNames() = 0; 60 : 61 : /** 62 : * Set the solution to a given vector. 63 : * @param soln The vector which should be treated as the solution. 64 : */ 65 : void setSolution(const NumericVector<Number> & soln); 66 : 67 : /** 68 : * Enable solution under/over-relaxation for fixed point iterations. 69 : * 70 : * Intended for segregated multi-system fixed point iterations where the system is solved 71 : * repeatedly with coefficients that depend on other systems/loops (e.g. deferred correction). 72 : * A value of 1 disables relaxation. 73 : * 74 : * The relaxed update is: 75 : * u <- relaxation_factor * u_new + (1 - relaxation_factor) * u_old 76 : */ 77 : void setFixedPointRelaxationFactor(const Real relaxation_factor); 78 : void clearFixedPointRelaxation(); 79 : void saveOldSolutionForFixedPointRelaxation(); 80 : void applyFixedPointRelaxation(); 81 : 82 : /** 83 : * Set the side on which the preconditioner is applied to. 84 : * @param pcs The required preconditioning side 85 : */ 86 : void setPCSide(MooseEnum pcs); 87 : 88 : /** 89 : * Get the current preconditioner side. 90 : */ 91 375285 : Moose::PCSideType getPCSide() { return _pc_side; } 92 : 93 : /** 94 : * Set the norm in which the linear convergence will be measured. 95 : * @param kspnorm The required norm 96 : */ 97 : void setMooseKSPNormType(MooseEnum kspnorm); 98 : 99 : /** 100 : * Get the norm in which the linear convergence is measured. 101 : */ 102 375285 : Moose::MooseKSPNormType getMooseKSPNormType() { return _ksp_norm; } 103 : 104 : virtual const NumericVector<Number> * const & currentSolution() const override final; 105 : 106 : virtual void compute(ExecFlagType type) override; 107 : 108 : protected: 109 : void checkInvalidSolution(); 110 : 111 : virtual NumericVector<Number> & solutionInternal() const override final; 112 : 113 : /** 114 : * Whether a system matrix is formed from coloring. This influences things like when to compute 115 : * time derivatives 116 : */ 117 4252 : virtual bool matrixFromColoring() const { return false; } 118 : 119 : /// solution vector from solver 120 : const NumericVector<Number> * _current_solution; 121 : 122 : /// Preconditioning side 123 : Moose::PCSideType _pc_side; 124 : /// KSP norm type 125 : Moose::MooseKSPNormType _ksp_norm; 126 : 127 : /// Boolean to see if solution is invalid 128 : bool _solution_is_invalid; 129 : 130 : /// Used for relaxing entire system solution during fixed point (multi-)system iterations 131 : Real _fixed_point_relaxation_factor = 1.0; 132 : }; 133 : 134 : inline const NumericVector<Number> * const & 135 219063194 : SolverSystem::currentSolution() const 136 : { 137 219063194 : return _current_solution; 138 : } 139 : 140 : inline NumericVector<Number> & 141 60766 : SolverSystem::solutionInternal() const 142 : { 143 60766 : return *system().solution; 144 : }