https://mooseframework.inl.gov
MFEMDataCollection.C
Go to the documentation of this file.
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 
16 {
18  params.addClassDescription("Output for controlling MFEMDataCollection inherited data.");
19  params.addParam<std::string>("submesh",
20  "Submesh to output variables on. Leave blank to use base mesh.");
21  params.addParam<std::vector<VariableName>>(
22  "show", {}, "A list of variables that should be included in the collection.");
23  params.addParam<std::vector<VariableName>>(
24  "hide", {}, "A list of variables that should NOT be included in the collection.");
25  return params;
26 }
27 
29  : FileOutput(parameters),
30  _problem_data(static_cast<MFEMProblem *>(_problem_ptr)->getProblemData()),
31  _pmesh(parameters.isParamValid("submesh")
32  ? _problem_data.submeshes.GetRef(getParam<std::string>("submesh"))
33  : const_cast<mfem::ParMesh &>(*_problem_data.pmesh.get())),
34  _shown(getParam<std::vector<VariableName>>("show")),
35  _hidden(getParam<std::vector<VariableName>>("hide"))
36 {
37 }
38 
39 void
41 {
42  // Save real fields
43  mfem::DataCollection & dc(getDataCollection());
44 
45  for (auto const & [gf_name, gf_ptr] : _problem_data.gridfunctions)
46  {
47  if ((_shown.size() && std::find(_shown.begin(), _shown.end(), gf_name) == _shown.end()) ||
48  std::find(_hidden.begin(), _hidden.end(), gf_name) != _hidden.end())
49  continue;
50  else if (dc.GetMesh() == gf_ptr->FESpace()->GetMesh())
51  dc.RegisterField(gf_name, gf_ptr.get());
52  else
53  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  for (auto const & [gf_name, gf_ptr] : _problem_data.cmplx_gridfunctions)
60  {
61  if ((_shown.size() && std::find(_shown.begin(), _shown.end(), gf_name) == _shown.end()) ||
62  std::find(_hidden.begin(), _hidden.end(), gf_name) != _hidden.end())
63  continue;
64  else if (dc.GetMesh() == gf_ptr->FESpace()->GetMesh())
65  {
66  dc.RegisterField(gf_name + "_real", &gf_ptr->real());
67  dc.RegisterField(gf_name + "_imag", &gf_ptr->imag());
68  }
69  else
70  mooseInfo("The variable ",
71  gf_name,
72  " is not defined on the same mesh as the output DataCollection.");
73  }
74 }
75 
76 void
77 MFEMDataCollection::setFileBaseInternal(const std::string & file_base)
78 {
80  getDataCollection().SetPrefixPath(_file_base);
81 }
82 
83 void
85 {
86  mfem::DataCollection & dc(getDataCollection());
87  // Write fields to disk
88  dc.SetCycle(getFileNumber());
89  dc.SetTime(time());
90  dc.Save();
91  ++_file_num;
92 }
93 
94 #endif
const std::vector< VariableName > & _hidden
List of variables to hide.
virtual void setFileBaseInternal(const std::string &file_base)
Internal function that sets the file_base.
Definition: FileOutput.C:126
void mooseInfo(Args &&... args) const
Definition: MooseBase.h:344
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
Definition: KokkosUtils.h:40
Moose::MFEM::ComplexGridFunctions cmplx_gridfunctions
virtual Real time() override
Get the output time.
Definition: PetscOutput.C:262
MFEMProblemData & _problem_data
Reference to the MFEMProblemData struct storing the output variables.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
unsigned int getFileNumber()
Return the current file number for this outputter.
Definition: FileOutput.C:180
std::string _file_base
The base filename from the input paramaters.
Definition: FileOutput.h:89
const std::vector< VariableName > & _shown
List of variables to show.
static InputParameters validParams()
Definition: FileOutput.C:24
void registerFields()
Register fields (GridFunctions) to be saved in the DataCollection.
MFEMDataCollection(const InputParameters &parameters)
static InputParameters validParams()
void output() override
Write out data.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
unsigned int & _file_num
A file number counter, initialized to 0 (this must be controlled by the child class, see Exodus)
Definition: FileOutput.h:80
An outputter with filename support.
Definition: FileOutput.h:20
virtual mfem::DataCollection & getDataCollection()=0
Moose::MFEM::GridFunctions gridfunctions
void setFileBaseInternal(const std::string &file_base) override
Update the DataCollection path when the internal file base path is set.
const Elem & get(const ElemType type_in)