https://mooseframework.inl.gov
ExodusFileTimes.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 #include "ExodusFileTimes.h"
11 #include "MooseUtils.h"
12 #include "libmesh/serial_mesh.h"
13 #include "libmesh/exodusII_io.h"
14 
16 
19 {
21  params.addClassDescription("Import times from one or more Exodus files.");
22  params.addRequiredParam<std::vector<FileName>>("files", "Exodus file(s) with the times");
23  // File is loaded only on zeroth process
24  params.set<bool>("auto_broadcast") = true;
25  // Exodus file set the time sequence during initialization stage
26  params.set<bool>("dynamic_time_sequence") = false;
27 
28  return params;
29 }
30 
31 ExodusFileTimes::ExodusFileTimes(const InputParameters & parameters) : Times(parameters)
32 {
33  // Reading exodus files on all ranks could be expensive
34  const auto & times_files = getParam<std::vector<FileName>>("files");
35 
36  if (processor_id() == 0)
37  {
38  for (const auto p_file_it : index_range(times_files))
39  {
40  // Check that the required file exists
41  MooseUtils::checkFileReadable(times_files[p_file_it]);
42 
43  // dummy mesh
44  ReplicatedMesh mesh(_communicator);
45 
46  libMesh::ExodusII_IO exodusII_io(mesh);
47  exodusII_io.read(times_files[p_file_it]);
48  auto & times = exodusII_io.get_time_steps();
49 
50  for (const auto & d : times)
51  _times.push_back(d);
52  }
53  }
54 
55  // Sort all the times, but also broadcast to other ranks
56  finalize();
57 }
static InputParameters validParams()
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
MeshBase & mesh
Times objects are under the hood Reporters, but limited to a vector of Real.
Definition: Times.h:18
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const Parallel::Communicator & _communicator
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
static InputParameters validParams()
Definition: Times.C:14
Times from one or more Exodus files.
bool checkFileReadable(const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true, bool check_for_git_lfs_pointer=true)
Checks to see if a file is readable (exists and permissions)
Definition: MooseUtils.C:250
const std::vector< Real > & get_time_steps()
ExodusFileTimes(const InputParameters &parameters)
virtual void read(const std::string &name) override
registerMooseObject("MooseApp", ExodusFileTimes)
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...
virtual void finalize() override
In charge of reduction across all ranks.
Definition: Times.C:124
processor_id_type processor_id() const
auto index_range(const T &sizable)
std::vector< Real > & _times
The vector holding the times.
Definition: Times.h:74