https://mooseframework.inl.gov
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
EBSDMeshGenerator Class Reference

Mesh generated from parameters read from a DREAM3D EBSD file. More...

#include <EBSDMeshGenerator.h>

Inheritance diagram for EBSDMeshGenerator:
[legend]

Classes

struct  Geometry
 

Public Types

typedef DataFileName DataFileParameterType
 

Public Member Functions

 EBSDMeshGenerator (const InputParameters &parameters)
 
std::unique_ptr< MeshBase > generate () override
 
const GeometrygetEBSDGeometry () const
 
const std::string & getEBSDFilename () const
 
std::unique_ptr< MeshBase > generateInternal ()
 
const std::set< MeshGeneratorName > & getRequestedMeshGenerators () const
 
const std::set< MeshGeneratorName > & getRequestedMeshGeneratorsForSub () const
 
void addParentMeshGenerator (const MeshGenerator &mg, const AddParentChildKey)
 
void addChildMeshGenerator (const MeshGenerator &mg, const AddParentChildKey)
 
const std::set< const MeshGenerator *, Comparator > & getParentMeshGenerators () const
 
const std::set< const MeshGenerator *, Comparator > & getChildMeshGenerators () const
 
const std::set< const MeshGenerator *, Comparator > & getSubMeshGenerators () const
 
bool isParentMeshGenerator (const MeshGeneratorName &name, const bool direct=true) const
 
bool isChildMeshGenerator (const MeshGeneratorName &name, const bool direct=true) const
 
bool isNullMeshName (const MeshGeneratorName &name) const
 
bool hasSaveMesh () const
 
bool hasOutput () const
 
const std::string & getSavedMeshName () const
 
bool hasGenerateData () const
 
bool isDataOnly () const
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
virtual const std::string & name () const
 
std::string typeAndName () const
 
std::string errorPrefix (const std::string &error_type) const
 
void callMooseError (std::string msg, const bool with_prefix) const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
const InputParametersparameters () const
 
MooseObjectName uniqueName () const
 
const T & getParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const T * queryParam (const std::string &name) const
 
const T & getRenamedParam (const std::string &old_name, const std::string &new_name) const
 
getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &nm) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void mooseError (Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static InputParameters validParams ()
 
static bool hasGenerateData (const InputParameters &params)
 
static void setHasGenerateData (InputParameters &params)
 

Public Attributes

const ConsoleStream _console
 

Static Public Attributes

static const std::string data_only_param
 
static constexpr auto SYSTEM
 
static constexpr auto NAME
 

Protected Member Functions

std::unique_ptr< MeshBase > & buildMeshSubgenerator ()
 
void readEBSDHeader ()
 Read the EBSD data file header. More...
 
virtual void generateData ()
 
T & copyMeshProperty (const std::string &target_data_name, const std::string &source_data_name, const std::string &source_mesh)
 
T & copyMeshProperty (const std::string &source_data_name, const std::string &source_mesh)
 
std::unique_ptr< MeshBase > & getMesh (const std::string &param_name, const bool allow_invalid=false)
 
std::vector< std::unique_ptr< MeshBase > *> getMeshes (const std::string &param_name)
 
std::unique_ptr< MeshBase > & getMeshByName (const MeshGeneratorName &mesh_generator_name)
 
std::vector< std::unique_ptr< MeshBase > *> getMeshesByName (const std::vector< MeshGeneratorName > &mesh_generator_names)
 
void declareMeshForSub (const std::string &param_name)
 
void declareMeshesForSub (const std::string &param_name)
 
void declareMeshForSubByName (const MeshGeneratorName &mesh_generator_name)
 
void declareMeshesForSubByName (const std::vector< MeshGeneratorName > &mesh_generator_names)
 
std::unique_ptr< MeshBase > buildMeshBaseObject (unsigned int dim=libMesh::invalid_uint)
 
std::unique_ptr< ReplicatedMesh > buildReplicatedMesh (unsigned int dim=libMesh::invalid_uint)
 
std::unique_ptr< DistributedMesh > buildDistributedMesh (unsigned int dim=libMesh::invalid_uint)
 
void addMeshSubgenerator (const std::string &type, const std::string &name, Ts... extra_input_parameters)
 
void addMeshSubgenerator (const std::string &type, const std::string &name, InputParameters params)
 
void declareNullMeshName (const MeshGeneratorName &name)
 
const T & getMeshProperty (const std::string &data_name, const std::string &prefix)
 
const T & getMeshProperty (const std::string &data_name)
 
bool hasMeshProperty (const std::string &data_name, const std::string &prefix) const
 
bool hasMeshProperty (const std::string &data_name, const std::string &prefix) const
 
bool hasMeshProperty (const std::string &data_name) const
 
bool hasMeshProperty (const std::string &data_name) const
 
std::string meshPropertyName (const std::string &data_name) const
 
T & declareMeshProperty (const std::string &data_name, Args &&... args)
 
T & declareMeshProperty (const std::string &data_name, const T &data_value)
 
T & declareMeshProperty (const std::string &data_name, Args &&... args)
 
T & declareMeshProperty (const std::string &data_name, const T &data_value)
 
T & setMeshProperty (const std::string &data_name, Args &&... args)
 
T & setMeshProperty (const std::string &data_name, const T &data_value)
 
T & setMeshProperty (const std::string &data_name, Args &&... args)
 
T & setMeshProperty (const std::string &data_name, const T &data_value)
 

Static Protected Member Functions

static std::string meshPropertyName (const std::string &data_name, const std::string &prefix)
 

Protected Attributes

const bool _distributed
 are we working on a distributed mesh? More...
 
const FileName & _filename
 Name of the file containing the EBSD data. More...
 
Geometry _geometry
 EBSD data file mesh information. More...
 
const unsigned int _pre_refine
 
std::unique_ptr< MeshBase > & _base
 
MooseMesh *const _mesh
 
const bool & _enabled
 
MooseApp_app
 
const std::string _type
 
const std::string _name
 
const InputParameters_pars
 
Factory_factory
 
ActionFactory_action_factory
 
const Parallel::Communicator & _communicator
 

Detailed Description

Mesh generated from parameters read from a DREAM3D EBSD file.

Definition at line 19 of file EBSDMeshGenerator.h.

Constructor & Destructor Documentation

◆ EBSDMeshGenerator()

EBSDMeshGenerator::EBSDMeshGenerator ( const InputParameters parameters)

Definition at line 45 of file EBSDMeshGenerator.C.

48  _filename(getParam<FileName>("filename")),
49  _pre_refine(isParamValid("pre_refine") ? getParam<unsigned int>("pre_refine")
50  : getParam<unsigned int>("uniform_refine")),
52 {
53 }
MeshGenerator(const InputParameters &parameters)
const bool _distributed
are we working on a distributed mesh?
MooseMesh *const _mesh
const unsigned int _pre_refine
bool isParamValid(const std::string &name) const
const FileName & _filename
Name of the file containing the EBSD data.
std::unique_ptr< MeshBase > & _base
const InputParameters & parameters() const
virtual bool isDistributedMesh() const
std::unique_ptr< MeshBase > & buildMeshSubgenerator()

Member Function Documentation

◆ buildMeshSubgenerator()

std::unique_ptr< MeshBase > & EBSDMeshGenerator::buildMeshSubgenerator ( )
protected

Definition at line 56 of file EBSDMeshGenerator.C.

57 {
59 
60  const auto generator_type =
61  _distributed ? "DistributedRectilinearMeshGenerator" : "GeneratedMeshGenerator";
62  auto params = _app.getFactory().getValidParams(generator_type);
63 
64  params.set<MooseEnum>("dim") = (_geometry.dim == 1 ? "1" : (_geometry.dim == 2 ? "2" : "3"));
65 
66  std::array<unsigned int, 3> nr;
67  nr[0] = _geometry.n[0];
68  nr[1] = _geometry.n[1];
69  nr[2] = _geometry.n[2];
70 
71  // set min/max box length
72  params.set<Real>("xmin") = _geometry.min[0];
73  params.set<Real>("xmax") = nr[0] * _geometry.d[0] + _geometry.min[0];
74  params.set<Real>("ymin") = _geometry.min[1];
75  params.set<Real>("ymax") = nr[1] * _geometry.d[1] + _geometry.min[1];
76  params.set<Real>("zmin") = _geometry.min[2];
77  params.set<Real>("zmax") = nr[2] * _geometry.d[2] + _geometry.min[2];
78 
79  // check if the requested uniform refine level is possible and determine initial grid size
80  for (auto i : make_range(_geometry.dim))
81  {
82  auto factor = MathUtils::pow(2, _pre_refine);
83  if (nr[i] % factor != 0)
84  paramError("pre_refine",
85  "EBSDMeshGenerator error. Requested levels of pre refinement not possible.");
86  nr[i] /= factor;
87  }
88 
89  if (_distributed)
90  {
91  params.set<dof_id_type>("nx") = nr[0];
92  params.set<dof_id_type>("ny") = nr[1];
93  params.set<dof_id_type>("nz") = nr[2];
94  params.set<processor_id_type>("num_cores_for_partition") =
95  isParamValid("num_cores_for_partition")
96  ? getParam<processor_id_type>("num_cores_for_partition")
97  : 0;
98  }
99  else
100  {
101  params.set<unsigned int>("nx") = nr[0];
102  params.set<unsigned int>("ny") = nr[1];
103  params.set<unsigned int>("nz") = nr[2];
104  }
105 
106  addMeshSubgenerator(generator_type, name() + "_base_mesh", params);
107  return getMeshByName(name() + "_base_mesh");
108 }
std::unique_ptr< MeshBase > & getMeshByName(const MeshGeneratorName &mesh_generator_name)
T & set(const std::string &name, bool quiet_mode=false)
InputParameters getValidParams(const std::string &name) const
virtual const std::string & name() const
const bool _distributed
are we working on a distributed mesh?
Factory & getFactory()
void readEBSDHeader()
Read the EBSD data file header.
const unsigned int _pre_refine
bool isParamValid(const std::string &name) const
uint8_t processor_id_type
void addMeshSubgenerator(const std::string &type, const std::string &name, Ts... extra_input_parameters)
std::array< Real, 3 > min
void paramError(const std::string &param, Args... args) const
std::array< Real, 3 > d
Geometry _geometry
EBSD data file mesh information.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
MooseApp & _app
IntRange< T > make_range(T beg, T end)
std::array< unsigned int, 3 > n
T pow(T x, int e)
uint8_t dof_id_type

◆ generate()

std::unique_ptr< MeshBase > EBSDMeshGenerator::generate ( )
overridevirtual

Implements MeshGenerator.

Definition at line 191 of file EBSDMeshGenerator.C.

192 {
193  if (_pre_refine)
194  {
195  libMesh::MeshRefinement mesh_refinement(*_base);
196  mesh_refinement.uniformly_refine(_pre_refine);
197  }
198  return std::move(_base);
199 }
const unsigned int _pre_refine
std::unique_ptr< MeshBase > & _base

◆ getEBSDFilename()

const std::string& EBSDMeshGenerator::getEBSDFilename ( ) const
inline

Definition at line 42 of file EBSDMeshGenerator.h.

Referenced by EBSDReader::readFile().

42 { return _filename; }
const FileName & _filename
Name of the file containing the EBSD data.

◆ getEBSDGeometry()

const Geometry& EBSDMeshGenerator::getEBSDGeometry ( ) const
inline

Definition at line 41 of file EBSDMeshGenerator.h.

Referenced by EBSDReader::readFile().

41 { return _geometry; }
Geometry _geometry
EBSD data file mesh information.

◆ readEBSDHeader()

void EBSDMeshGenerator::readEBSDHeader ( )
protected

Read the EBSD data file header.

Definition at line 111 of file EBSDMeshGenerator.C.

Referenced by buildMeshSubgenerator().

112 {
113  std::ifstream stream_in(_filename.c_str());
114 
115  if (!stream_in)
116  paramError("filename", "Can't open EBSD file: ", _filename);
117 
118  // Labels to look for in the header
119  const std::vector<std::string> labels = {
120  "x_step", "x_dim", "y_step", "y_dim", "z_step", "z_dim", "x_min", "y_min", "z_min"};
121 
122  // Dimension variables to store once they are found in the header
123  // X_step, X_Dim, Y_step, Y_Dim, Z_step, Z_Dim
124  // We use Reals even though the Dim values should all be integers...
125  std::vector<Real> label_vals(labels.size(), 0.0);
126 
127  std::string line;
128  while (std::getline(stream_in, line))
129  {
130  // We need to process the comment lines that have:
131  // X_step, X_Dim
132  // Y_step, Y_Dim
133  // Z_step, Z_Dim
134  // in them. The labels are case insensitive.
135  if (line.find("#") == 0)
136  {
137  // Process lines that start with a comment character (comments and meta data)
138  std::transform(line.begin(), line.end(), line.begin(), ::tolower);
139 
140  for (unsigned i = 0; i < labels.size(); ++i)
141  if (line.find(labels[i]) != std::string::npos)
142  {
143  std::string dummy;
144  std::istringstream iss(line);
145  iss >> dummy >> dummy >> label_vals[i];
146 
147  // One label per line, break out of for loop over labels
148  break;
149  }
150  }
151  else
152  // first non comment line marks the end of the header
153  break;
154  }
155 
156  // Copy stuff out of the label_vars array into class variables
157  _geometry.d[0] = label_vals[0];
158  _geometry.n[0] = label_vals[1];
159  _geometry.min[0] = label_vals[6];
160 
161  _geometry.d[1] = label_vals[2];
162  _geometry.n[1] = label_vals[3];
163  _geometry.min[1] = label_vals[7];
164 
165  _geometry.d[2] = label_vals[4];
166  _geometry.n[2] = label_vals[5];
167  _geometry.min[2] = label_vals[8];
168 
169  unsigned int dim;
170 
171  // determine mesh dimension
172  for (dim = 3; dim > 0 && _geometry.n[dim - 1] == 0; --dim)
173  ;
174 
175  // check if the data has nonzero stepsizes
176  for (unsigned i = 0; i < dim; ++i)
177  {
178  if (_geometry.n[i] == 0)
179  mooseError("Error reading header, EBSD grid size is zero.");
180  if (_geometry.d[i] == 0.0)
181  mooseError("Error reading header, EBSD data step size is zero.");
182  }
183 
184  if (dim == 0)
185  mooseError("Error reading header, EBSD data is zero dimensional.");
186 
187  _geometry.dim = dim;
188 }
unsigned int dim
std::array< Real, 3 > min
void paramError(const std::string &param, Args... args) const
std::array< Real, 3 > d
Geometry _geometry
EBSD data file mesh information.
const FileName & _filename
Name of the file containing the EBSD data.
void mooseError(Args &&... args) const
std::array< unsigned int, 3 > n

◆ validParams()

InputParameters EBSDMeshGenerator::validParams ( )
static

Definition at line 22 of file EBSDMeshGenerator.C.

Referenced by EBSDMeshErrorTest::testParam().

23 {
25  params.addClassDescription("Mesh generated from a specified DREAM.3D EBSD data file.");
26  params.addRequiredParam<FileName>("filename", "The name of the file containing the EBSD data");
27 
28  params.addDeprecatedParam<unsigned int>("uniform_refine",
29  "Deprecated. Use `pre_refine` instead.",
30  "Deprecated. Use `pre_refine` instead.");
31  params.addParam<unsigned int>(
32  "pre_refine",
33  0,
34  "Number of coarsening levels available in adaptive mesh refinement. The resulting mesh will "
35  "have one mesh element per EBSD data cell, but will be based on a refined coarser mesh with "
36  "'pre_refine' levels of refinement. This requires all dimension of the EBSD data to be "
37  "divisible by 2^pre_refine.(this parameter was formerly called 'uniform_refine')");
38 
40  "num_cores_for_partition",
41  "Number of cores for partitioning the graph (dafaults to the number of MPI ranks)");
42  return params;
43 }
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
uint8_t processor_id_type
static InputParameters validParams()
void addClassDescription(const std::string &doc_string)

Member Data Documentation

◆ _base

std::unique_ptr<MeshBase>& EBSDMeshGenerator::_base
protected

Definition at line 63 of file EBSDMeshGenerator.h.

Referenced by generate().

◆ _distributed

const bool EBSDMeshGenerator::_distributed
protected

are we working on a distributed mesh?

Definition at line 51 of file EBSDMeshGenerator.h.

Referenced by buildMeshSubgenerator().

◆ _filename

const FileName& EBSDMeshGenerator::_filename
protected

Name of the file containing the EBSD data.

Definition at line 54 of file EBSDMeshGenerator.h.

Referenced by getEBSDFilename(), and readEBSDHeader().

◆ _geometry

Geometry EBSDMeshGenerator::_geometry
protected

EBSD data file mesh information.

Definition at line 57 of file EBSDMeshGenerator.h.

Referenced by buildMeshSubgenerator(), getEBSDGeometry(), and readEBSDHeader().

◆ _pre_refine

const unsigned int EBSDMeshGenerator::_pre_refine
protected

Definition at line 60 of file EBSDMeshGenerator.h.

Referenced by buildMeshSubgenerator(), and generate().


The documentation for this class was generated from the following files: