Line data Source code
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 : #pragma once 11 : 12 : #include "GeneralUserObject.h" 13 : #include "MooseEnum.h" 14 : #include "DelimitedFileReader.h" 15 : 16 : /** 17 : * Read properties from file - grain, element, node or block 18 : * Input file syntax: prop1 prop2 etc. See test. 19 : * For grain level, voronoi tesellation with random grain centers are generated; 20 : * Element center points used for assigning properties 21 : * Usable for generated mesh 22 : * For sorting by elements: the CSV data should be sorted by element ID 23 : * For sorting by nodes: the CSV data should be organized by node ID 24 : * For block type, elements inside one block are assigned identical material properties; 25 : */ 26 : 27 : class PropertyReadFile : public GeneralUserObject 28 : { 29 : public: 30 : static InputParameters validParams(); 31 : 32 : PropertyReadFile(const InputParameters & parameters); 33 528 : virtual ~PropertyReadFile() {} 34 : 35 : /// Retrieve the property file names from the parameters 36 : std::vector<FileName> getFileNames(); 37 : 38 : virtual void initialize(); 39 284 : virtual void execute() {} 40 284 : virtual void finalize() {} 41 : 42 : /** 43 : * This function reads the data from file 44 : */ 45 : void readData(); 46 : 47 : /** 48 : * This function generates voronoi tesselation center points 49 : * Presently random generated 50 : */ 51 : virtual void initVoronoiCenterPoints(); 52 : 53 : /** 54 : * This function retrieves property data for elements 55 : * @param elem the element to get data for 56 : * @param prop_num the column index of the property we want to retrieve 57 : * @return the property value for the element 58 : */ 59 : Real getData(const Elem * const elem, const unsigned int prop_num) const; 60 : 61 : /** 62 : * This function retrieves properties for elements, from a file that has element-based data 63 : * @param elem the element to get data for 64 : * @param prop_num the column index of the property we want to retrieve 65 : * @return the property value for the element 66 : */ 67 : Real getElementData(const Elem * const elem, const unsigned int prop_num) const; 68 : 69 : /** 70 : * This function retrieves properties for nodes, from a file that has node-based data 71 : * @param node the node to get the data for 72 : * @param prop_num the column index of the property we want to retrieve 73 : * @return the property value for the node 74 : */ 75 : Real getNodeData(const Node * const node, const unsigned int prop_num) const; 76 : 77 : /** 78 : * This function retrieves properties for elements from a file with nearest neighbor / grain based 79 : * properties. Voronoi centers distribution in the RVE can be Periodic or non-periodic (default) 80 : * @param point the location to get data for 81 : * @param prop_num the column index of the property we want to retrieve 82 : * @return the property value for the element 83 : */ 84 : Real getVoronoiData(const Point & point, const unsigned int prop_num) const; 85 : 86 : /** 87 : * This function retrieves properties for elements, from a file that has block-based data 88 : * @param elem the element to get data for 89 : * @param prop_num the column index of the property we want to retrieve 90 : * @return the property value for the element 91 : */ 92 : Real getBlockData(const Elem * const elem, const unsigned int prop_num) const; 93 : 94 : /** 95 : * This function calculates minimum distance between 2 points 96 : * considering periodicity of the simulation volume 97 : * @return the minimum distance between two points 98 : */ 99 : Real minPeriodicDistance(const Point &, const Point &) const; 100 : 101 : /** 102 : * How data is organized in the CSV file 103 : */ 104 : enum class ReadTypeEnum 105 : { 106 : ELEMENT = 0, 107 : VORONOI = 1, 108 : BLOCK = 2, 109 : NODE = 3, 110 : GRAIN = 4 111 : }; 112 : 113 : /** 114 : * Returns the ordering of data expected in the CSV file 115 : */ 116 302 : ReadTypeEnum getReadType() const { return _read_type; } 117 : 118 : /** 119 : * Returns the number of properties (columns) read in the file 120 : */ 121 302 : unsigned int getNumProperties() const { return _nprop; } 122 : 123 : protected: 124 : /// Name of file containing property values 125 : std::vector<FileName> _prop_file_names; 126 : /// Index of the file we last read 127 : unsigned int & _current_file_index; 128 : /// Use DelimitedFileReader to read and store data from file 129 : MooseUtils::DelimitedFileReader _reader; 130 : 131 : /// Type of read - element, grain, or block 132 : const ReadTypeEnum _read_type; 133 : 134 : /// Parameters for the nearest neighbor / grain interpolation 135 : /// Whether to use a random tesselation for the Voronoi/grain type 136 : const bool _use_random_tesselation; 137 : /// Random seed - used for generating grain centers 138 : const unsigned int _rand_seed; 139 : /// Type of voronoi tesselation/grain structure - non-periodic default 140 : const MooseEnum _rve_type; 141 : /// Do the block numbers start with zero or one? 142 : bool _block_zero; 143 : 144 : /// Legacy attribute to keep Grizzly functional, see idaholab/moose#19109, idaholab/Grizzly#182 145 : const unsigned int _ngrain; 146 : 147 : MooseMesh & _mesh; 148 : std::vector<Point> _center; 149 : 150 : private: 151 : /// Bounding box for the mesh 152 : BoundingBox _bounding_box; 153 : 154 : /// Class attributes useful for range-checking 155 : /// Number of properties in a row 156 : const unsigned int _nprop; 157 : /// Number of grains (for reading a CSV file with properties ordered by grains) 158 : const unsigned int _nvoronoi; 159 : /// Number of blocks (for reading a CSV file with properties ordered by blocks) 160 : const unsigned int _nblock; 161 : 162 : /// To keep track of initialization to avoid reading the files twice 163 : bool & _initialize_called_once; 164 : 165 : /// Whether to read the first CSV file in the constructor or on the first initialization before execution 166 : const bool _load_on_construction; 167 : };