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 : * Set the side on which the preconditioner is applied to. 69 : * @param pcs The required preconditioning side 70 : */ 71 : void setPCSide(MooseEnum pcs); 72 : 73 : /** 74 : * Get the current preconditioner side. 75 : */ 76 370226 : Moose::PCSideType getPCSide() { return _pc_side; } 77 : 78 : /** 79 : * Set the norm in which the linear convergence will be measured. 80 : * @param kspnorm The required norm 81 : */ 82 : void setMooseKSPNormType(MooseEnum kspnorm); 83 : 84 : /** 85 : * Get the norm in which the linear convergence is measured. 86 : */ 87 370226 : Moose::MooseKSPNormType getMooseKSPNormType() { return _ksp_norm; } 88 : 89 : virtual const NumericVector<Number> * const & currentSolution() const override final; 90 : 91 : virtual void compute(ExecFlagType type) override; 92 : 93 : protected: 94 : void checkInvalidSolution(); 95 : 96 : virtual NumericVector<Number> & solutionInternal() const override final; 97 : 98 : /** 99 : * Whether a system matrix is formed from coloring. This influences things like when to compute 100 : * time derivatives 101 : */ 102 4203 : virtual bool matrixFromColoring() const { return false; } 103 : 104 : /// solution vector from solver 105 : const NumericVector<Number> * _current_solution; 106 : 107 : /// Preconditioning side 108 : Moose::PCSideType _pc_side; 109 : /// KSP norm type 110 : Moose::MooseKSPNormType _ksp_norm; 111 : 112 : /// Boolean to see if solution is invalid 113 : bool _solution_is_invalid; 114 : }; 115 : 116 : inline const NumericVector<Number> * const & 117 280209443 : SolverSystem::currentSolution() const 118 : { 119 280209443 : return _current_solution; 120 : } 121 : 122 : inline NumericVector<Number> & 123 56610 : SolverSystem::solutionInternal() const 124 : { 125 56610 : return *system().solution; 126 : }