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 "MFEMTransient.h" 13 : #include "MFEMProblem.h" 14 : #include "TimeDomainEquationSystemProblemOperator.h" 15 : 16 : registerMooseObject("MooseApp", MFEMTransient); 17 : 18 : InputParameters 19 8728 : MFEMTransient::validParams() 20 : { 21 8728 : InputParameters params = MFEMExecutioner::validParams(); 22 8728 : params.addClassDescription("Executioner for transient MFEM problems."); 23 8728 : params.addParam<Real>("start_time", 0.0, "The start time of the simulation"); 24 8728 : params.addParam<Real>("end_time", 1.0e30, "The end time of the simulation"); 25 8728 : params.addParam<Real>("dt", 1., "The timestep size between solves"); 26 26184 : params.addParam<unsigned int>( 27 17456 : "visualisation_steps", 1, "The number of timesteps in a transient run"); 28 8728 : return params; 29 0 : } 30 : 31 49 : MFEMTransient::MFEMTransient(const InputParameters & params) 32 : : MFEMExecutioner(params), 33 49 : _t_step(getParam<Real>("dt")), 34 49 : _t_initial(getParam<Real>("start_time")), 35 49 : _t_final(getParam<Real>("end_time")), 36 49 : _t(_mfem_problem.time()), 37 49 : _it(0), 38 49 : _vis_steps(params.get<unsigned int>("visualisation_steps")), 39 98 : _last_step(false) 40 : { 41 49 : _app.setStartTime(_t_initial); 42 49 : _t = _t_initial; 43 49 : _mfem_problem.transient(true); 44 49 : } 45 : 46 : void 47 49 : MFEMTransient::constructProblemOperator() 48 : { 49 49 : _problem_data.eqn_system = std::make_shared<Moose::MFEM::TimeDependentEquationSystem>(); 50 : auto problem_operator = 51 49 : std::make_unique<Moose::MFEM::TimeDomainEquationSystemProblemOperator>(_problem_data); 52 49 : _problem_operator.reset(); 53 49 : _problem_operator = std::move(problem_operator); 54 49 : } 55 : 56 : void 57 140 : MFEMTransient::step(double dt, int) const 58 : { 59 : // Check if current time step is final 60 140 : if (_t + dt >= _t_final - dt / 2) 61 : { 62 49 : _last_step = true; 63 : } 64 : 65 : // Advance time step. 66 140 : _problem_data.ode_solver->Step(_problem_data.f, _t, dt); 67 : 68 : // Synchonise time dependent GridFunctions with updated DoF data. 69 140 : _problem_operator->SetTestVariablesFromTrueVectors(); 70 : 71 : // Execute user objects at timestep end 72 140 : _mfem_problem.execute(EXEC_TIMESTEP_END); 73 : // Perform the output of the current time step 74 140 : _mfem_problem.outputStep(EXEC_TIMESTEP_END); 75 140 : } 76 : 77 : void 78 49 : MFEMTransient::init() 79 : { 80 49 : _mfem_problem.execute(EXEC_PRE_MULTIAPP_SETUP); 81 49 : _mfem_problem.initialSetup(); 82 : 83 : // Set up initial conditions 84 49 : _problem_data.eqn_system->Init( 85 49 : _problem_data.gridfunctions, 86 49 : _problem_data.fespaces, 87 98 : getParam<MooseEnum>("assembly_level").getEnum<mfem::AssemblyLevel>()); 88 : 89 49 : _problem_operator->SetGridFunctions(); 90 49 : _problem_operator->Init(_problem_data.f); 91 : 92 : // Set timestepper 93 49 : _problem_data.ode_solver = std::make_unique<mfem::BackwardEulerSolver>(); 94 49 : _problem_data.ode_solver->Init(*(_problem_operator)); 95 49 : _problem_operator->SetTime(0.0); 96 49 : } 97 : 98 : void 99 49 : MFEMTransient::execute() 100 : { 101 49 : _mfem_problem.outputStep(EXEC_INITIAL); 102 49 : preExecute(); 103 : 104 189 : while (_last_step != true) 105 : { 106 140 : _it++; 107 140 : step(_t_step, _it); 108 : } 109 : 110 49 : _mfem_problem.finishMultiAppStep(EXEC_MULTIAPP_FIXED_POINT_BEGIN, 111 : /*recurse_through_multiapp_levels=*/true); 112 49 : _mfem_problem.finishMultiAppStep(EXEC_TIMESTEP_BEGIN, /*recurse_through_multiapp_levels=*/true); 113 49 : _mfem_problem.finishMultiAppStep(EXEC_TIMESTEP_END, /*recurse_through_multiapp_levels=*/true); 114 49 : _mfem_problem.finishMultiAppStep(EXEC_MULTIAPP_FIXED_POINT_END, 115 : /*recurse_through_multiapp_levels=*/true); 116 : 117 49 : TIME_SECTION("final", 1, "Executing Final Objects"); 118 49 : _mfem_problem.execMultiApps(EXEC_FINAL); 119 49 : _mfem_problem.finalizeMultiApps(); 120 49 : _mfem_problem.execute(EXEC_FINAL); 121 49 : _mfem_problem.outputStep(EXEC_FINAL); 122 49 : _mfem_problem.postExecute(); 123 : 124 49 : postExecute(); 125 49 : } 126 : 127 : #endif