https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
39void
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
76void
77MFEMDataCollection::setFileBaseInternal(const std::string & file_base)
78{
80 getDataCollection().SetPrefixPath(_file_base);
81}
82
83void
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
void mooseInfo(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
Definition MooseError.h:401
An outputter with filename support.
Definition FileOutput.h:21
unsigned int getFileNumber()
Return the current file number for this outputter.
Definition FileOutput.C:180
static InputParameters validParams()
Definition FileOutput.C:24
std::string _file_base
The base filename from the input paramaters.
Definition FileOutput.h:89
virtual void setFileBaseInternal(const std::string &file_base)
Internal function that sets the file_base.
Definition FileOutput.C:126
unsigned int & _file_num
A file number counter, initialized to 0 (this must be controlled by the child class,...
Definition FileOutput.h:80
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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 output() override
Write out data.
const std::vector< VariableName > & _hidden
List of variables to hide.
void registerFields()
Register fields (GridFunctions) to be saved in the DataCollection.
virtual mfem::DataCollection & getDataCollection()=0
MFEMProblemData & _problem_data
Reference to the MFEMProblemData struct storing the output variables.
MFEMDataCollection(const InputParameters &parameters)
const std::vector< VariableName > & _shown
List of variables to show.
void setFileBaseInternal(const std::string &file_base) override
Update the DataCollection path when the internal file base path is set.
static InputParameters validParams()
virtual Real time() override
Get the output time.
Moose::MFEM::ComplexGridFunctions cmplx_gridfunctions
Moose::MFEM::GridFunctions gridfunctions