https://mooseframework.inl.gov
Loading...
Searching...
No Matches
XDA.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// MOOSE includes
11#include "XDA.h"
12#include "MooseApp.h"
13#include "FEProblem.h"
14#include "MooseMesh.h"
15
16// libMesh includes
17#include "libmesh/enum_xdr_mode.h"
18
20registerMooseObjectAliased("MooseApp", XDA, "XDR");
21
24{
25 // Get the base class parameters
27
28 // Add description for the XDA class
29 params.addClassDescription("Object for outputting data in the XDA/XDR format.");
30
31 /* Set a private parameter for controlling the output type (XDR = binary), the value
32 of this parameter is set by the AddOutputAction*/
33 params.addPrivateParam<bool>("_binary", false);
34
35 // Return the InputParameters
36 return params;
37}
38
39XDA::XDA(const InputParameters & parameters)
40 : SampledOutput(parameters), _binary(getParam<bool>("_binary"))
41{
42}
43
44void
46{
47 // Strings for the two filenames to be written
48 std::string es_name = filename();
49 std::string mesh_name = es_name;
50
51 // Make sure the filename has an extension
52 if (es_name.size() < 4)
53 mooseError("Unacceptable filename, you must include an extension (.xda or .xdr).");
54
55 // Insert the mesh suffix
56 mesh_name.insert(mesh_name.size() - 4, "_mesh");
57
58 // Set the binary flag
60
61 // Write the files
62 _mesh_ptr->getMesh().write(mesh_name);
64 es_name, mode, EquationSystems::WRITE_DATA | EquationSystems::WRITE_ADDITIONAL_DATA);
65 _file_num++;
66}
67
68std::string
70{
71 // Append the padded time step to the file base
72 std::ostringstream output;
73 output << _file_base << "_" << std::setw(_padding) << std::setprecision(0) << std::setfill('0')
74 << std::right << _file_num;
75
76 if (_binary)
77 output << ".xdr";
78 else
79 output << ".xda";
80 return output.str();
81}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
registerMooseObject("MooseApp", XDA)
registerMooseObjectAliased("MooseApp", XDA, "XDR")
unsigned int _padding
Number of digits to pad the extensions.
Definition FileOutput.h:83
std::string _file_base
The base filename from the input paramaters.
Definition FileOutput.h:89
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 addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
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.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3557
libMesh::EquationSystems * _es_ptr
Reference the the libMesh::EquationSystems object that contains the data.
Definition Output.h:194
MooseMesh * _mesh_ptr
A convenience pointer to the current mesh (reference or displaced depending on "use_displaced")
Definition Output.h:197
Based class for providing re-positioning and oversampling support to output objects.
static InputParameters validParams()
Class for output data to the XDAII format.
Definition XDA.h:19
static InputParameters validParams()
Definition XDA.C:23
XDA(const InputParameters &parameters)
Class consturctor.
Definition XDA.C:39
bool _binary
Flag for binary output.
Definition XDA.h:45
virtual void output() override
Overload the Output::output method, this is required for XDA output due to the method utlized for out...
Definition XDA.C:45
virtual std::string filename() override
Returns the current filename, this method handles adding the timestep suffix.
Definition XDA.C:69
void write(std::string_view name, const XdrMODE, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true) const