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;
119 std::vector<FileName>
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 ",
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.");
345 unsigned int ivoronoi = 0;
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 readData()
This function reads the data from file.
virtual Real getMaxInDimension(unsigned int component) const
BoundingBox _bounding_box
Bounding box for the mesh.
virtual Real getMinInDimension(unsigned int component) const
Returns the min or max of the requested dimension respectively.
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...
A MultiMooseEnum object to hold "execute_on" flags.
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...
std::vector< FileName > _prop_file_names
Name of file containing property values.
std::vector< Point > _center
unsigned int & _current_file_index
Index of the file we last read.
const ReadTypeEnum _read_type
Type of read - element, grain, or block.
static InputParameters validParams()
PropertyReadFile(const InputParameters ¶meters)
void mooseInfo(Args &&... args) const
registerMooseObjectRenamed("MooseApp", ElementPropertyReadFile, "06/30/2021 24:00", PropertyReadFile)
Read properties from file - grain, element, node or block Input file syntax: prop1 prop2 etc...
const MooseEnum _rve_type
Type of voronoi tesselation/grain structure - non-periodic default.
MooseUtils::DelimitedFileReader _reader
Use DelimitedFileReader to read and store data from file.
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.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
static InputParameters validParams()
Real getData(const Elem *const elem, const unsigned int prop_num) const
This function retrieves property data for elements.
Real minPeriodicDistance(const Point &, const Point &) const
This function calculates minimum distance between 2 points considering periodicity of the simulation ...
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
auto max(const L &left, const R &right)
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
const unsigned int _rand_seed
Random seed - used for generating grain centers.
const unsigned int _nvoronoi
Number of grains (for reading a CSV file with properties ordered by grains)
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...
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
ReadTypeEnum
How data is organized in the CSV file.
void setFormatFlag(FormatFlag value)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
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 ...
void read()
Perform the actual data reading.
const ExecFlagType EXEC_LINEAR
const std::vector< std::vector< T > > & getData() const
Return the rows/columns of data.
virtual dof_id_type nNodes() const
Calls n_nodes/elem() on the underlying libMesh mesh object.
const bool _load_on_construction
Whether to read the first CSV file in the constructor or on the first initialization before execution...
const ExecFlagType EXEC_NONLINEAR
const unsigned int _nblock
Number of blocks (for reading a CSV file with properties ordered by blocks)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Utility class for reading delimited data (e.g., CSV data).
static void seed(unsigned int seed)
The method seeds the random number generator.
const bool _use_random_tesselation
Parameters for the nearest neighbor / grain interpolation Whether to use a random tesselation for the...
IntRange< T > make_range(T beg, T end)
void setHeaderFlag(HeaderFlag value)
static Real rand()
This method returns the next random number (Real format) from the generator.
void removeAvailableFlags(const ExecFlagType &flag, Args... flags)
Remove flags from being available.
libMesh::BoundingBox buildBoundingBox(const Point &p1, const Point &p2)
Construct a valid bounding box from 2 arbitrary points.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
const unsigned int _nprop
Class attributes useful for range-checking Number of properties in a row.
virtual void initVoronoiCenterPoints()
This function generates voronoi tesselation center points Presently random generated.
bool _block_zero
Do the block numbers start with zero or one?
registerMooseObject("MooseApp", PropertyReadFile)
auto min(const L &left, const R &right)
std::vector< FileName > getFileNames()
Retrieve the property file names from the parameters.
const ExecFlagType EXEC_FINAL
void ErrorVector unsigned int
virtual void initialize()
Called before execute() is ever called so that data can be cleared.
virtual dof_id_type nElem() const
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 ExecFlagType EXEC_INITIAL