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 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  return params;
22 }
23 
25  : FileOutput(parameters),
26  _problem_data(static_cast<MFEMProblem *>(_problem_ptr)->getProblemData()),
27  _pmesh(parameters.isParamValid("submesh")
28  ? _problem_data.submeshes.GetRef(getParam<std::string>("submesh"))
29  : const_cast<mfem::ParMesh &>(*_problem_data.pmesh.get()))
30 {
31 }
32 
33 void
35 {
36  mfem::DataCollection & dc(getDataCollection());
37  for (auto const & [gf_name, gf_ptr] : _problem_data.gridfunctions)
38  {
39  if (dc.GetMesh() == gf_ptr->FESpace()->GetMesh())
40  dc.RegisterField(gf_name, gf_ptr.get());
41  else
42  mooseInfo("The variable ",
43  gf_name,
44  " is not defined on the same mesh as the output DataCollection.");
45  }
46 }
47 
48 void
50 {
51  mfem::DataCollection & dc(getDataCollection());
52  // Write fields to disk
53  dc.SetCycle(getFileNumber());
54  dc.SetTime(time());
55  dc.Save();
56  _file_num++;
57 }
58 
59 #endif
void mooseInfo(Args &&... args) const
virtual Real time() override
Get the output time.
Definition: PetscOutput.C:262
MFEMProblemData & _problem_data
Reference to the MFEMProblemData struct storing the output variables.
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1155
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
static InputParameters validParams()
Definition: FileOutput.C:24
MFEMDataCollection(const InputParameters &parameters)
static InputParameters validParams()
void output() override
Overload this function with the desired output activities.
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