www.mooseframework.org
Nemesis.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "Nemesis.h"
16 
17 // MOOSE includes
18 #include "FEProblem.h"
19 #include "MooseApp.h"
20 #include "MooseMesh.h"
21 #include "MooseVariableScalar.h"
22 #include "SystemBase.h"
23 
24 #include "libmesh/dof_map.h"
25 #include "libmesh/nemesis_io.h"
26 
27 template <>
30 {
31  // Get the base class parameters
33  params += AdvancedOutput::enableOutputTypes("scalar postprocessor input");
34 
35  // Add description for the Nemesis class
36  params.addClassDescription("Object for output data in the Nemesis format");
37 
38  // Return the InputParameters
39  return params;
40 }
41 
42 Nemesis::Nemesis(const InputParameters & parameters)
43  : AdvancedOutput(parameters),
44  _nemesis_io_ptr(nullptr),
45  _file_num(0),
46  _nemesis_num(0),
47  _nemesis_initialized(false)
48 {
49 }
50 
52 
53 void
55 {
56 
58 
59  // Make certain that a Nemesis_IO object exists
60  meshChanged();
61 }
62 
63 void
65 {
66  // Do not delete the Nemesis_IO object if it has not been used; also there is no need to setup
67  // the object in this case, so just return
68  if (_nemesis_io_ptr != nullptr && !_nemesis_initialized)
69  return;
70 
71  // Increment the file number
72  _file_num++;
73 
74  // Reset the number of outputs for this file
75  _nemesis_num = 1;
76 
77  // Create the new NemesisIO object
78  _nemesis_io_ptr = libmesh_make_unique<Nemesis_IO>(_problem_ptr->mesh().getMesh());
79  _nemesis_initialized = false;
80 }
81 
82 void
84 {
85  // List of desired postprocessor outputs
86  const std::set<std::string> & pps = getPostprocessorOutput();
87 
88  // Append the postprocessor data to the global name value parameters; scalar outputs
89  // also append these member variables
90  for (const auto & name : pps)
91  {
92  _global_names.push_back(name);
94  }
95 }
96 
97 void
99 {
100  // List of desired scalar outputs
101  const std::set<std::string> & out = getScalarOutput();
102 
103  // Append the scalar to the global output lists
104  for (const auto & out_name : out)
105  {
106  // Make sure scalar values are in sync with the solution vector
107  // and are visible on this processor. See TableOutput.C for
108  // TableOutput::outputScalarVariables() explanatory comments
109 
110  MooseVariableScalar & scalar_var = _problem_ptr->getScalarVariable(0, out_name);
111  scalar_var.reinit();
112  VariableValue value = scalar_var.sln();
113 
114  const std::vector<dof_id_type> & dof_indices = scalar_var.dofIndices();
115  const unsigned int n = dof_indices.size();
116  value.resize(n);
117 
118  const DofMap & dof_map = scalar_var.sys().dofMap();
119  for (unsigned int i = 0; i != n; ++i)
120  {
121  const processor_id_type pid = dof_map.dof_owner(dof_indices[i]);
122  this->comm().broadcast(value[i], pid);
123  }
124 
125  // If the scalar has a single component, output the name directly
126  if (n == 1)
127  {
128  _global_names.push_back(out_name);
129  _global_values.push_back(value[0]);
130  }
131 
132  // If the scalar as many components add indices to the end of the name
133  else
134  {
135  for (unsigned int i = 0; i < n; ++i)
136  {
137  std::ostringstream os;
138  os << out_name << "_" << i;
139  _global_names.push_back(os.str());
140  _global_values.push_back(value[i]);
141  }
142  }
143  }
144 }
145 
146 void
148 {
149  if (!shouldOutput(type))
150  return;
151 
152  // Clear the global variables (postprocessors and scalars)
153  _global_names.clear();
154  _global_values.clear();
155 
156  // Call the output methods
158 
159  // Write the data
160  _nemesis_io_ptr->write_timestep(
162  _nemesis_initialized = true;
163 
164  // Increment output call counter for the current file
165  _nemesis_num++;
166 
167  // Write the global variables (populated by the output methods)
168  if (!_global_values.empty())
169  _nemesis_io_ptr->write_global_data(_global_values, _global_names);
170 }
171 
172 std::string
174 {
175  // Append the .e extension on the base file name
176  std::ostringstream output;
177  output << _file_base << ".e";
178 
179  // Add the _000x extension to the file
180  if (_file_num > 1)
181  output << "-s" << std::setw(_padding) << std::setprecision(0) << std::setfill('0') << std::right
182  << _file_num;
183 
184  // Return the filename
185  return output.str();
186 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
const std::set< std::string > & getPostprocessorOutput()
The list of postprocessor names that are set for output.
virtual void initialSetup() override
Sets up the libMesh::NemesisII_IO object used for outputting to the Nemesis format.
Definition: Nemesis.C:54
std::vector< Real > _global_values
Storage for scalar values (postprocessors and scalar AuxVariables)
Definition: Nemesis.h:87
VariableValue & sln()
Real getGlobalTimeOffset()
Each App has it&#39;s own local time.
Definition: MooseApp.h:207
void resize(const unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:205
virtual Real time() override
Get the output time.
Definition: PetscOutput.C:258
virtual void outputScalarVariables() override
Writes scalar AuxVariables to global output parameters.
Definition: Nemesis.C:98
std::vector< std::string > _global_names
Storage for names of the above scalar values.
Definition: Nemesis.h:90
unsigned int _nemesis_num
Count of outputs per exodus file.
Definition: Nemesis.h:97
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::string _file_base
The base filename from the input paramaters.
Definition: FileOutput.h:87
InputParameters validParams< Nemesis >()
Definition: Nemesis.C:29
InputParameters validParams< AdvancedOutput >()
unsigned int _padding
Number of digits to pad the extensions.
Definition: FileOutput.h:93
virtual DofMap & dofMap()
Gets the dof map.
Definition: SystemBase.C:610
const std::set< std::string > & getScalarOutput()
The list of scalar variables names that are set for output.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2408
EquationSystems * _es_ptr
Reference the the libMesh::EquationSystems object that contains the data.
Definition: Output.h:180
virtual void output(const ExecFlagType &type)
A single call to this function should output all the necessary data for a single timestep.
DofMap & dof_map
virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid, const std::string &var_name) override
Returns the scalar variable reference from whichever system contains it.
virtual bool shouldOutput(const ExecFlagType &type)
Handles logic for determining if a step should be output.
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
Definition: Output.h:171
static InputParameters enableOutputTypes(const std::string &names=std::string())
A method for enabling individual output type control.
Based class for output objects.
MatType type
virtual void initialSetup()
Initialization method.
std::vector< dof_id_type > & dofIndices()
bool _nemesis_initialized
Flag if the output has been initialized.
Definition: Nemesis.h:100
PetscInt n
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:108
Class for scalar variables (they are different).
MPI_Comm comm
virtual MooseMesh & mesh() override
virtual void output(const ExecFlagType &type) override
Overload the Output::output method, this is required for Nemesis output due to the method utilized fo...
Definition: Nemesis.C:147
PostprocessorValue & getPostprocessorValue(const PostprocessorName &name)
Get a reference to the value associated with the postprocessor.
ExecFlagType
Execution flags - when is the object executed/evaluated.
Definition: MooseTypes.h:90
virtual void outputPostprocessors() override
Writes postprocessor values to global output parameters.
Definition: Nemesis.C:83
unsigned int _file_num
Current output filename; utilized by filename() to create the proper suffix.
Definition: Nemesis.h:93
virtual void meshChanged() override
Creates a new NemesisII_IO output object for outputing a new mesh.
Definition: Nemesis.C:64
virtual std::string filename() override
Returns the current filename, this method handles the -s000 suffix common to NemesisII files...
Definition: Nemesis.C:173
SystemBase & sys()
Get the system this variable is part of.
Nemesis(const InputParameters &parameters)
Class constructor.
Definition: Nemesis.C:42
virtual ~Nemesis()
Class destructor.
Definition: Nemesis.C:51
std::unique_ptr< Nemesis_IO > _nemesis_io_ptr
Pointer to the libMesh::NemesisII_IO object that performs the actual data output. ...
Definition: Nemesis.h:84