26 params.
addClassDescription(
"User Object to read property data from an external file and assign "
27 "it to elements / nodes / subdomains etc.");
30 params.
addParam<std::vector<FileName>>(
32 "Name(s) of the property file name. If specifying multiple files, the next file will be read "
33 "at initialization right before every execution");
34 params.
addParam<FileName>(
"prop_file_names_csv",
35 "Name(s) of a CSV file containing the list of the property file names "
36 "as its first column, with no header.");
39 params.
addRequiredParam<
unsigned int>(
"nprop",
"Number of tabulated property values");
41 "nvoronoi", 0,
"Number of voronoi tesselations/grains/nearest neighbor regions");
43 "ngrain",
"Number of grains.",
"ngrain is deprecated, use nvoronoi instead");
44 params.
addParam<
unsigned int>(
"nblock", 0,
"Number of blocks");
46 MooseEnum(
"element voronoi block node grain"),
47 "Type of property distribution: "
50 "voronoi:nearest neighbor / voronoi grain structure "
51 "block:by mesh block "
52 "grain: deprecated, use voronoi");
53 params.
addParam<
bool>(
"use_random_voronoi",
55 "Wether to generate random positions for the Voronoi tesselation");
56 params.
addParam<
unsigned int>(
"rand_seed", 2000,
"random seed");
60 "Periodic or non-periodic grain distribution: Default is non-periodic");
62 "use_zero_based_block_indexing",
true,
"Are the blocks numbered starting at zero?");
66 "load_first_file_on_construction",
68 "Whether to read the first CSV file on construction or on the first execution");
74 params.
setDocString(
"execute_on", exec_enum.getDocString());
76 params.
set<
bool>(
"force_preaux") =
true;
83 _prop_file_names(getFileNames()),
84 _current_file_index(declareRestartableData<unsigned
int>(
"file_index", 0)),
87 _prop_file_names[
std::min(_current_file_index, (unsigned
int)_prop_file_names.size() - 1)]),
89 _use_random_tesselation(getParam<bool>(
"use_random_voronoi")),
90 _rand_seed(getParam<unsigned
int>(
"rand_seed")),
91 _rve_type(getParam<
MooseEnum>(
"rve_type")),
92 _block_zero(getParam<bool>(
"use_zero_based_block_indexing")),
93 _ngrain(isParamValid(
"ngrain") ? getParam<unsigned
int>(
"ngrain")
94 : getParam<unsigned
int>(
"nvoronoi")),
95 _mesh(_fe_problem.
mesh()),
96 _nprop(getParam<unsigned
int>(
"nprop")),
97 _nvoronoi(isParamValid(
"ngrain") ? getParam<unsigned
int>(
"ngrain")
98 : getParam<unsigned
int>(
"nvoronoi")),
99 _nblock(getParam<unsigned
int>(
"nblock")),
100 _initialize_called_once(declareRestartableData<bool>(
"initialize_called", false)),
101 _load_on_construction(getParam<bool>(
"load_first_file_on_construction"))
105 "Random seeds should only be provided if random tesselation is desired");
107 Point mesh_min, mesh_max;
122 std::vector<FileName> prop_file_names;
125 prop_file_names = getParam<std::vector<FileName>>(
"prop_file_name");
129 getParam<FileName>(
"prop_file_names_csv"));
131 file_name_reader.
read();
132 if (file_name_reader.
getData().size())
134 const auto fdata = file_name_reader.
getData(0);
135 for (
const auto & fname : fdata)
136 prop_file_names.push_back(fname);
141 "The names of the property files must be provided with either 'prop_file_name' "
142 "or 'prop_file_names_csv'. Providing both or none is not supported.");
143 if (prop_file_names.empty())
144 paramError(
"prop_file_name",
"A property file should have been specified.");
145 return prop_file_names;
165 mooseInfo(
"Last file specified has been read. The file will no longer be updated.");
172 mooseWarning(
"CSV data is sorted by element, but mesh element renumbering is on, be careful!");
174 mooseWarning(
"CSV data is sorted by node, but mesh node renumbering is on, be careful!");
179 unsigned int nobjects = 0;
193 paramError(
"nvoronoi",
"Provide non-zero number of voronoi tesselations/grains.");
200 paramError(
"ngrain",
"Provide non-zero number of voronoi tesselations/grains.");
206 paramError(
"nblock",
"Provide non-zero number of blocks.");
215 " does not have enough rows for ",
223 " objects, some data will not be used.");
224 for (
unsigned int i = 0; i < nobjects; i++)
230 " has number of data less than ",
248 for (
const auto i : make_range(
_nvoronoi))
256 for (
const auto i : make_range(
_nvoronoi))
267 "nprop",
"Property number ", prop_num,
" greater than total number of properties ",
_nprop);
291 "PropertyReadFile has data sorted by node, it should note be retrieved by element");
300 unsigned int jelem = elem->id();
304 " greater than than total number of element in mesh: ",
306 ". Elements should be numbered consecutively, and ids should start from 0.");
313 unsigned int jnode = node->id();
317 " greater than than total number of nodes in mesh: ",
319 ". Nodes should be numbered consecutively, with ids starting from 0.");
326 unsigned int offset = 0;
330 unsigned int elem_subdomain_id = elem->subdomain_id();
331 if (elem_subdomain_id >=
_nblock + offset)
335 " greater than than total number of blocks in mesh: ",
337 ". Blocks should be numbered consecutively, starting from 0.");
344 Real min_dist = std::numeric_limits<Real>::max();
345 unsigned int ivoronoi = 0;
347 for (
const auto i : make_range(
_nvoronoi))
361 Point dist_vec =
_center[i] - point;
362 dist = dist_vec.norm();
378 Point dist_vec = c - p;
379 Real min_dist = dist_vec.norm();
381 Real fac[3] = {-1.0, 0.0, 1.0};
382 for (
unsigned int i = 0; i < 3; i++)
383 for (
unsigned int j = 0; j < 3; j++)
384 for (
unsigned int k = 0; k < 3; k++)
392 Real dist = dist_vec.norm();
void mooseInfo(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
const ExecFlagType EXEC_INITIAL
const ExecFlagType EXEC_LINEAR
const ExecFlagType EXEC_NONLINEAR
const ExecFlagType EXEC_FINAL
registerMooseObject("MooseApp", PropertyReadFile)
registerMooseObjectRenamed("MooseApp", ElementPropertyReadFile, "06/30/2021 24:00", PropertyReadFile)
void ErrorVector unsigned int
A MultiMooseEnum object to hold "execute_on" flags.
void removeAvailableFlags(const ExecFlagType &flag, Args... flags)
Remove flags from being available.
static InputParameters validParams()
const InputParameters & parameters() const
Get the parameters of the object.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
virtual Real getMaxInDimension(unsigned int component) const
virtual dof_id_type nNodes() const
Calls n_nodes/elem() on the underlying libMesh mesh object.
virtual Real getMinInDimension(unsigned int component) const
Returns the min or max of the requested dimension respectively.
virtual dof_id_type nElem() const
static Real rand()
This method returns the next random number (Real format) from the generator.
static void seed(unsigned int seed)
The method seeds the random number generator.
Utility class for reading delimited data (e.g., CSV data).
const std::vector< std::vector< T > > & getData() const
Return the rows/columns of data.
void setHeaderFlag(HeaderFlag value)
void setFormatFlag(FormatFlag value)
void setFileName(const std::string &new_file)
Set the file name, used to change the file to read from We also reset the column/row names as a secon...
void read()
Perform the actual data reading.
Read properties from file - grain, element, node or block Input file syntax: prop1 prop2 etc.
Real getData(const Elem *const elem, const unsigned int prop_num) const
This function retrieves property data for elements.
Real getElementData(const Elem *const elem, const unsigned int prop_num) const
This function retrieves properties for elements, from a file that has element-based data.
const unsigned int _rand_seed
Random seed - used for generating grain centers.
const bool _use_random_tesselation
Parameters for the nearest neighbor / grain interpolation Whether to use a random tesselation for the...
unsigned int & _current_file_index
Index of the file we last read.
Real getVoronoiData(const Point &point, const unsigned int prop_num) const
This function retrieves properties for elements from a file with nearest neighbor / grain based prope...
bool _block_zero
Do the block numbers start with zero or one?
std::vector< FileName > _prop_file_names
Name of file containing property values.
BoundingBox _bounding_box
Bounding box for the mesh.
Real getNodeData(const Node *const node, const unsigned int prop_num) const
This function retrieves properties for nodes, from a file that has node-based data.
MooseUtils::DelimitedFileReader _reader
Use DelimitedFileReader to read and store data from file.
void readData()
This function reads the data from file.
virtual void initVoronoiCenterPoints()
This function generates voronoi tesselation center points Presently random generated.
virtual void initialize()
Called before execute() is ever called so that data can be cleared.
PropertyReadFile(const InputParameters ¶meters)
bool & _initialize_called_once
To keep track of initialization to avoid reading the files twice.
Real getBlockData(const Elem *const elem, const unsigned int prop_num) const
This function retrieves properties for elements, from a file that has block-based data.
const ReadTypeEnum _read_type
Type of read - element, grain, or block.
const unsigned int _nblock
Number of blocks (for reading a CSV file with properties ordered by blocks)
const MooseEnum _rve_type
Type of voronoi tesselation/grain structure - non-periodic default.
std::vector< Point > _center
const unsigned int _nvoronoi
Number of grains (for reading a CSV file with properties ordered by grains)
std::vector< FileName > getFileNames()
Retrieve the property file names from the parameters.
static InputParameters validParams()
Real minPeriodicDistance(const Point &, const Point &) const
This function calculates minimum distance between 2 points considering periodicity of the simulation ...
ReadTypeEnum
How data is organized in the CSV file.
const unsigned int _nprop
Class attributes useful for range-checking Number of properties in a row.
const bool _load_on_construction
Whether to read the first CSV file in the constructor or on the first initialization before execution...
BoundingBox buildBoundingBox(const Point &p1, const Point &p2)
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.