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 
26  return params;
27 }
28 
29 ExodusFileTimes::ExodusFileTimes(const InputParameters & parameters) : Times(parameters)
30 {
31  // Reading exodus files on all ranks could be expensive
32  const auto & times_files = getParam<std::vector<FileName>>("files");
33 
34  if (processor_id() == 0)
35  {
36  for (const auto p_file_it : index_range(times_files))
37  {
38  // Check that the required file exists
39  MooseUtils::checkFileReadable(times_files[p_file_it]);
40 
41  // dummy mesh
42  ReplicatedMesh mesh(_communicator);
43 
44  libMesh::ExodusII_IO exodusII_io(mesh);
45  exodusII_io.read(times_files[p_file_it]);
46  auto & times = exodusII_io.get_time_steps();
47 
48  for (const auto & d : times)
49  _times.push_back(d);
50  }
51  }
52 
53  // Sort all the times, but also broadcast to other ranks
54  finalize();
55 }
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:117
processor_id_type processor_id() const
auto index_range(const T &sizable)
std::vector< Real > & _times
The vector holding the times.
Definition: Times.h:72