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 7566 : MFEMDataCollection::validParams() 16 : { 17 7566 : InputParameters params = FileOutput::validParams(); 18 15132 : params.addClassDescription("Output for controlling MFEMDataCollection inherited data."); 19 30264 : params.addParam<std::string>("submesh", 20 : "Submesh to output variables on. Leave blank to use base mesh."); 21 30264 : params.addParam<std::vector<VariableName>>( 22 : "show", {}, "A list of variables that should be included in the collection."); 23 22698 : params.addParam<std::vector<VariableName>>( 24 : "hide", {}, "A list of variables that should NOT be included in the collection."); 25 7566 : return params; 26 0 : } 27 : 28 636 : MFEMDataCollection::MFEMDataCollection(const InputParameters & parameters) 29 : : FileOutput(parameters), 30 636 : _problem_data(static_cast<MFEMProblem *>(_problem_ptr)->getProblemData()), 31 636 : _pmesh(parameters.isParamValid("submesh") 32 1383 : ? _problem_data.submeshes.GetRef(getParam<std::string>("submesh")) 33 525 : : const_cast<mfem::ParMesh &>(*_problem_data.pmesh.get())), 34 1272 : _shown(getParam<std::vector<VariableName>>("show")), 35 1908 : _hidden(getParam<std::vector<VariableName>>("hide")) 36 : { 37 636 : } 38 : 39 : void 40 636 : MFEMDataCollection::registerFields() 41 : { 42 : // Save real fields 43 636 : mfem::DataCollection & dc(getDataCollection()); 44 : 45 2593 : for (auto const & [gf_name, gf_ptr] : _problem_data.gridfunctions) 46 : { 47 3914 : if ((_shown.size() && std::find(_shown.begin(), _shown.end(), gf_name) == _shown.end()) || 48 3914 : std::find(_hidden.begin(), _hidden.end(), gf_name) != _hidden.end()) 49 7 : continue; 50 1950 : else if (dc.GetMesh() == gf_ptr->FESpace()->GetMesh()) 51 1371 : dc.RegisterField(gf_name, gf_ptr.get()); 52 : else 53 579 : 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 692 : for (auto const & [gf_name, gf_ptr] : _problem_data.cmplx_gridfunctions) 60 : { 61 112 : if ((_shown.size() && std::find(_shown.begin(), _shown.end(), gf_name) == _shown.end()) || 62 112 : std::find(_hidden.begin(), _hidden.end(), gf_name) != _hidden.end()) 63 0 : continue; 64 56 : else if (dc.GetMesh() == gf_ptr->FESpace()->GetMesh()) 65 : { 66 56 : dc.RegisterField(gf_name + "_real", &gf_ptr->real()); 67 56 : 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 636 : } 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 1476 : MFEMDataCollection::output() 85 : { 86 1476 : mfem::DataCollection & dc(getDataCollection()); 87 : // Write fields to disk 88 1476 : dc.SetCycle(getFileNumber()); 89 1476 : dc.SetTime(time()); 90 1476 : dc.Save(); 91 1476 : ++_file_num; 92 1476 : } 93 : 94 : #endif