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 "MFEMDataCollection.h" 13 : 14 : InputParameters 15 7580 : MFEMDataCollection::validParams() 16 : { 17 7580 : InputParameters params = FileOutput::validParams(); 18 15160 : params.addClassDescription("Output for controlling MFEMDataCollection inherited data."); 19 22740 : params.addParam<std::string>("submesh", 20 : "Submesh to output variables on. Leave blank to use base mesh."); 21 7580 : return params; 22 0 : } 23 : 24 643 : MFEMDataCollection::MFEMDataCollection(const InputParameters & parameters) 25 : : FileOutput(parameters), 26 643 : _problem_data(static_cast<MFEMProblem *>(_problem_ptr)->getProblemData()), 27 643 : _pmesh(parameters.isParamValid("submesh") 28 1389 : ? _problem_data.submeshes.GetRef(getParam<std::string>("submesh")) 29 1183 : : const_cast<mfem::ParMesh &>(*_problem_data.pmesh.get())) 30 : { 31 643 : } 32 : 33 : void 34 643 : MFEMDataCollection::registerFields() 35 : { 36 : // Save real fields 37 643 : mfem::DataCollection & dc(getDataCollection()); 38 : 39 2495 : for (auto const & [gf_name, gf_ptr] : _problem_data.gridfunctions) 40 : { 41 1852 : if (dc.GetMesh() == gf_ptr->FESpace()->GetMesh()) 42 1307 : dc.RegisterField(gf_name, gf_ptr.get()); 43 : else 44 545 : mooseInfo("The variable ", 45 : gf_name, 46 : " is not defined on the same mesh as the output DataCollection."); 47 : } 48 : 49 : // Save complex fields 50 699 : for (auto const & [gf_name, gf_ptr] : _problem_data.cmplx_gridfunctions) 51 : { 52 56 : if (dc.GetMesh() == gf_ptr->FESpace()->GetMesh()) 53 : { 54 56 : dc.RegisterField(gf_name + "_real", &gf_ptr->real()); 55 56 : dc.RegisterField(gf_name + "_imag", &gf_ptr->imag()); 56 : } 57 : else 58 0 : mooseInfo("The variable ", 59 : gf_name, 60 : " is not defined on the same mesh as the output DataCollection."); 61 : } 62 643 : } 63 : 64 : void 65 24 : MFEMDataCollection::setFileBaseInternal(const std::string & file_base) 66 : { 67 24 : FileOutput::setFileBaseInternal(file_base); 68 24 : getDataCollection().SetPrefixPath(_file_base); 69 24 : } 70 : 71 : void 72 1634 : MFEMDataCollection::output() 73 : { 74 1634 : mfem::DataCollection & dc(getDataCollection()); 75 : // Write fields to disk 76 1634 : dc.SetCycle(getFileNumber()); 77 1634 : dc.SetTime(time()); 78 1634 : dc.Save(); 79 1634 : ++_file_num; 80 1634 : } 81 : 82 : #endif