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