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 : #ifdef MOOSE_MFEM_ENABLED 11 : 12 : #include "MFEMSteady.h" 13 : #include "MFEMProblem.h" 14 : #include "MFEMEigenproblem.h" 15 : #include "EigenproblemEquationSystem.h" 16 : #include "EquationSystemProblemOperator.h" 17 : #include "EigenproblemESProblemOperator.h" 18 : 19 : registerMooseObject("MooseApp", MFEMSteady); 20 : 21 : InputParameters 22 4336 : MFEMSteady::validParams() 23 : { 24 4336 : InputParameters params = MFEMProblemSolve::validParams(); 25 4336 : params += Executioner::validParams(); 26 8672 : params.addClassDescription("Executioner for steady state MFEM problems."); 27 13008 : params.addParam<Real>("time", 0.0, "System time"); 28 4336 : return params; 29 0 : } 30 : 31 1119 : MFEMSteady::MFEMSteady(const InputParameters & params) 32 : : Executioner(params), 33 1119 : _mfem_problem(dynamic_cast<MFEMProblem &>(feProblem())), 34 1119 : _mfem_problem_data(_mfem_problem.getProblemData()), 35 1119 : _mfem_problem_solve(*this, getProblemOperators()), 36 2238 : _system_time(getParam<Real>("time")), 37 1119 : _time_step(_mfem_problem.timeStep()), 38 2238 : _time([this]() -> Real & { return this->_mfem_problem.time() = this->_system_time; }()), 39 1119 : _last_solve_converged(false) 40 : { 41 : // If no ProblemOperators have been added by the user, add a default 42 1119 : if (getProblemOperators().empty()) 43 : { 44 1119 : if (_mfem_problem.getNumericType() == MFEMProblem::NumericType::REAL) 45 : { 46 1056 : if (dynamic_cast<MFEMEigenproblem *>(&_mfem_problem)) 47 : { 48 26 : _mfem_problem_data.eqn_system = std::make_shared<Moose::MFEM::EigenproblemEquationSystem>(); 49 : auto problem_operator = 50 26 : std::make_shared<Moose::MFEM::EigenproblemESProblemOperator>(_mfem_problem); 51 26 : addProblemOperator(std::move(problem_operator)); 52 26 : } 53 : else 54 : { 55 1030 : _mfem_problem_data.eqn_system = std::make_shared<Moose::MFEM::EquationSystem>(); 56 : auto problem_operator = 57 1030 : std::make_shared<Moose::MFEM::EquationSystemProblemOperator>(_mfem_problem); 58 1030 : addProblemOperator(std::move(problem_operator)); 59 1030 : } 60 : } 61 63 : else if (_mfem_problem.getNumericType() == MFEMProblem::NumericType::COMPLEX) 62 : { 63 63 : _mfem_problem_data.eqn_system = std::make_shared<Moose::MFEM::ComplexEquationSystem>(); 64 : auto problem_operator = 65 63 : std::make_shared<Moose::MFEM::ComplexEquationSystemProblemOperator>(_mfem_problem); 66 63 : addProblemOperator(std::move(problem_operator)); 67 63 : } 68 : else 69 0 : mooseError("Unknown numeric type. " 70 : "Please set the Problem numeric type to either 'real' or 'complex'."); 71 : } 72 1119 : } 73 : 74 : void 75 1119 : MFEMSteady::init() 76 : { 77 1119 : _mfem_problem.execute(EXEC_PRE_MULTIAPP_SETUP); 78 1119 : _mfem_problem.initialSetup(); 79 : 80 1119 : if (_mfem_problem_data.nonlinear_solver) 81 18 : _mfem_problem_data.eqn_system->SetSolverRequiresGradient( 82 18 : _mfem_problem_data.nonlinear_solver->RequiresGradient()); 83 : 84 : // Set up initial conditions 85 1119 : _mfem_problem_data.eqn_system->Init( 86 1119 : _mfem_problem_data.gridfunctions, 87 1119 : _mfem_problem_data.cmplx_gridfunctions, 88 4476 : getParam<MooseEnum>("assembly_level").getEnum<mfem::AssemblyLevel>()); 89 : 90 2238 : for (const auto & problem_operator : getProblemOperators()) 91 : { 92 1119 : problem_operator->SetGridFunctions(); 93 1119 : problem_operator->Init(_mfem_problem_data.f); 94 : } 95 1119 : } 96 : 97 : void 98 1119 : MFEMSteady::execute() 99 : { 100 1119 : if (_app.isRecovering()) 101 : { 102 0 : _console << "\nCannot recover steady solves!\nExiting...\n" << std::endl; 103 0 : return; 104 : } 105 : 106 1119 : _time_step = 0; 107 1119 : _time = _time_step; 108 1119 : _mfem_problem.outputStep(EXEC_INITIAL); 109 1119 : _time = _system_time; 110 : 111 1119 : preExecute(); 112 : 113 1119 : _mfem_problem.advanceState(); 114 : 115 : // first step in any steady state solve is always 1 (preserving backwards compatibility) 116 1119 : _time_step = 1; 117 1119 : _mfem_problem.timestepSetup(); 118 1119 : _mfem_problem.execTransfers(EXEC_TIMESTEP_BEGIN); 119 1119 : if (!_mfem_problem.execMultiApps(EXEC_TIMESTEP_BEGIN, true)) 120 : { 121 0 : _last_solve_converged = false; 122 0 : return; 123 : } 124 1119 : _mfem_problem.execute(EXEC_TIMESTEP_BEGIN); 125 : 126 1119 : _last_solve_converged = _mfem_problem_solve.solve(); 127 : 128 1119 : _mfem_problem.computeIndicators(); 129 1119 : _mfem_problem.computeMarkers(); 130 : 131 : // need to keep _time in sync with _time_step to get correct output 132 1119 : _time = _time_step; 133 1119 : _mfem_problem.execute(EXEC_TIMESTEP_END); 134 1119 : _mfem_problem.execTransfers(EXEC_TIMESTEP_END); 135 1119 : _mfem_problem.execMultiApps(EXEC_TIMESTEP_END, true); 136 1119 : _mfem_problem.outputStep(EXEC_TIMESTEP_END); 137 1119 : _time = _system_time; 138 : 139 : { 140 5595 : TIME_SECTION("final", 1, "Executing Final Objects") 141 1119 : _mfem_problem.execMultiApps(EXEC_FINAL); 142 1119 : _mfem_problem.finalizeMultiApps(); 143 1119 : _mfem_problem.postExecute(); 144 1119 : _mfem_problem.execute(EXEC_FINAL); 145 1119 : _time = _time_step; 146 1119 : _mfem_problem.outputStep(EXEC_FINAL); 147 1119 : _time = _system_time; 148 1119 : } 149 : 150 1119 : postExecute(); 151 : } 152 : 153 : #endif