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 7744 : MFEMDataCollection::validParams() 16 : { 17 7744 : InputParameters params = FileOutput::validParams(); 18 15488 : params.addClassDescription("Output for controlling MFEMDataCollection inherited data."); 19 30976 : params.addParam<std::string>("submesh", 20 : "Submesh to output variables on. Leave blank to use base mesh."); 21 30976 : params.addParam<std::vector<VariableName>>( 22 : "show", {}, "A list of variables that should be included in the collection."); 23 23232 : params.addParam<std::vector<VariableName>>( 24 : "hide", {}, "A list of variables that should NOT be included in the collection."); 25 7744 : return params; 26 0 : } 27 : 28 675 : MFEMDataCollection::MFEMDataCollection(const InputParameters & parameters) 29 : : FileOutput(parameters), 30 675 : _problem_data(static_cast<MFEMProblem *>(_problem_ptr)->getProblemData()), 31 675 : _pmesh(parameters.isParamValid("submesh") 32 1472 : ? _problem_data.submeshes.GetRef(getParam<std::string>("submesh")) 33 553 : : const_cast<mfem::ParMesh &>(*_problem_data.pmesh.get())), 34 1350 : _shown(getParam<std::vector<VariableName>>("show")), 35 2025 : _hidden(getParam<std::vector<VariableName>>("hide")) 36 : { 37 675 : } 38 : 39 : void 40 675 : MFEMDataCollection::registerFields() 41 : { 42 : // Save real fields 43 675 : mfem::DataCollection & dc(getDataCollection()); 44 : 45 2835 : for (auto const & [gf_name, gf_ptr] : _problem_data.gridfunctions) 46 : { 47 4320 : if ((_shown.size() && std::find(_shown.begin(), _shown.end(), gf_name) == _shown.end()) || 48 4320 : std::find(_hidden.begin(), _hidden.end(), gf_name) != _hidden.end()) 49 7 : continue; 50 2153 : else if (dc.GetMesh() == gf_ptr->FESpace()->GetMesh()) 51 1550 : dc.RegisterField(gf_name, gf_ptr.get()); 52 : else 53 603 : mooseInfo("The variable ", 54 : gf_name, 55 : " is not defined on the same mesh as the output DataCollection."); 56 : } 57 : 58 : // Save complex fields 59 739 : for (auto const & [gf_name, gf_ptr] : _problem_data.cmplx_gridfunctions) 60 : { 61 128 : if ((_shown.size() && std::find(_shown.begin(), _shown.end(), gf_name) == _shown.end()) || 62 128 : std::find(_hidden.begin(), _hidden.end(), gf_name) != _hidden.end()) 63 0 : continue; 64 64 : else if (dc.GetMesh() == gf_ptr->FESpace()->GetMesh()) 65 : { 66 64 : dc.RegisterField(gf_name + "_real", &gf_ptr->real()); 67 64 : dc.RegisterField(gf_name + "_imag", &gf_ptr->imag()); 68 : } 69 : else 70 0 : mooseInfo("The variable ", 71 : gf_name, 72 : " is not defined on the same mesh as the output DataCollection."); 73 : } 74 675 : } 75 : 76 : void 77 27 : MFEMDataCollection::setFileBaseInternal(const std::string & file_base) 78 : { 79 27 : FileOutput::setFileBaseInternal(file_base); 80 27 : getDataCollection().SetPrefixPath(_file_base); 81 27 : } 82 : 83 : void 84 1554 : MFEMDataCollection::output() 85 : { 86 1554 : mfem::DataCollection & dc(getDataCollection()); 87 : // Write fields to disk 88 1554 : dc.SetCycle(getFileNumber()); 89 1554 : dc.SetTime(time()); 90 1554 : dc.Save(); 91 1554 : ++_file_num; 92 1554 : } 93 : 94 : #endif