www.mooseframework.org
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
EBSDMesh Class Reference

Mesh generated from parameters. More...

#include <EBSDMesh.h>

Inheritance diagram for EBSDMesh:
[legend]

Classes

struct  EBSDMeshGeometry
 

Public Member Functions

 EBSDMesh (const InputParameters &parameters)
 
virtual ~EBSDMesh ()
 
virtual void buildMesh ()
 
const EBSDMeshGeometrygetEBSDGeometry () const
 
const std::string & getEBSDFilename () const
 

Protected Member Functions

void readEBSDHeader ()
 Read the EBSD data file header. More...
 

Protected Attributes

std::string _filename
 Name of the file containing the EBSD data. More...
 
EBSDMeshGeometry _geometry
 EBSD data file mesh information. More...
 

Detailed Description

Mesh generated from parameters.

Definition at line 25 of file EBSDMesh.h.

Constructor & Destructor Documentation

◆ EBSDMesh()

EBSDMesh::EBSDMesh ( const InputParameters &  parameters)

Definition at line 43 of file EBSDMesh.C.

44  : GeneratedMesh(parameters), _filename(getParam<FileName>("filename"))
45 {
46  if (_nx != 1 || _ny != 1 || _nz != 1)
47  mooseWarning("Do not specify mesh geometry information, it is read from the EBSD file.");
48 }
std::string _filename
Name of the file containing the EBSD data.
Definition: EBSDMesh.h:54

◆ ~EBSDMesh()

EBSDMesh::~EBSDMesh ( )
virtual

Definition at line 50 of file EBSDMesh.C.

50 {}

Member Function Documentation

◆ buildMesh()

void EBSDMesh::buildMesh ( )
virtual

Definition at line 133 of file EBSDMesh.C.

134 {
135  readEBSDHeader();
136 
137  unsigned int uniform_refine = getParam<unsigned int>("uniform_refine");
138  _dim = (_geometry.dim == 1 ? "1" : (_geometry.dim == 2 ? "2" : "3"));
139 
140  std::array<unsigned int, 3> nr;
141  nr[0] = _geometry.n[0];
142  nr[1] = _geometry.n[1];
143  nr[2] = _geometry.n[2];
144 
145  // set min/max box length
146  _xmin = _geometry.min[0];
147  _xmax = nr[0] * _geometry.d[0] + _geometry.min[0];
148  _ymin = _geometry.min[1];
149  _ymax = nr[1] * _geometry.d[1] + _geometry.min[1];
150  _zmin = _geometry.min[2];
151  _zmax = nr[2] * _geometry.d[2] + _geometry.min[2];
152 
153  // check if the requested uniform refine level is possible and determine initial grid size
154  for (unsigned int i = 0; i < uniform_refine; ++i)
155  for (unsigned int j = 0; j < _geometry.dim; ++j)
156  {
157  if (nr[j] % 2 != 0)
158  mooseError("EBSDMesh error. Requested uniform_refine levels not possible.");
159  nr[j] /= 2;
160  }
161 
162  _nx = nr[0];
163  _ny = nr[1];
164  _nz = nr[2];
165 
166  GeneratedMesh::buildMesh();
167 }
EBSDMeshGeometry _geometry
EBSD data file mesh information.
Definition: EBSDMesh.h:57
void readEBSDHeader()
Read the EBSD data file header.
Definition: EBSDMesh.C:53
std::array< unsigned int, 3 > n
Definition: EBSDMesh.h:42
std::array< Real, 3 > d
Definition: EBSDMesh.h:36
std::array< Real, 3 > min
Definition: EBSDMesh.h:38

◆ getEBSDFilename()

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

Definition at line 47 of file EBSDMesh.h.

Referenced by EBSDReader::readFile().

47 { return _filename; }
std::string _filename
Name of the file containing the EBSD data.
Definition: EBSDMesh.h:54

◆ getEBSDGeometry()

const EBSDMeshGeometry& EBSDMesh::getEBSDGeometry ( ) const
inline

Definition at line 46 of file EBSDMesh.h.

Referenced by EBSDReader::readFile().

46 { return _geometry; }
EBSDMeshGeometry _geometry
EBSD data file mesh information.
Definition: EBSDMesh.h:57

◆ readEBSDHeader()

void EBSDMesh::readEBSDHeader ( )
protected

Read the EBSD data file header.

Definition at line 53 of file EBSDMesh.C.

Referenced by buildMesh().

54 {
55  std::ifstream stream_in(_filename.c_str());
56 
57  if (!stream_in)
58  paramError("filename", "Can't open EBSD file: ", _filename);
59 
60  // Labels to look for in the header
61  std::vector<std::string> labels = {
62  "x_step", "x_dim", "y_step", "y_dim", "z_step", "z_dim", "x_min", "y_min", "z_min"};
63 
64  // Dimension variables to store once they are found in the header
65  // X_step, X_Dim, Y_step, Y_Dim, Z_step, Z_Dim
66  // We use Reals even though the Dim values should all be integers...
67  std::vector<Real> label_vals(labels.size(), 0.0);
68 
69  std::string line;
70  while (std::getline(stream_in, line))
71  {
72  // We need to process the comment lines that have:
73  // X_step, X_Dim
74  // Y_step, Y_Dim
75  // Z_step, Z_Dim
76  // in them. The labels are case insensitive.
77  if (line.find("#") == 0)
78  {
79  // Process lines that start with a comment character (comments and meta data)
80  std::transform(line.begin(), line.end(), line.begin(), ::tolower);
81 
82  for (unsigned i = 0; i < labels.size(); ++i)
83  if (line.find(labels[i]) != std::string::npos)
84  {
85  std::string dummy;
86  std::istringstream iss(line);
87  iss >> dummy >> dummy >> label_vals[i];
88 
89  // One label per line, break out of for loop over labels
90  break;
91  }
92  }
93  else
94  // first non comment line marks the end of the header
95  break;
96  }
97 
98  // Copy stuff out of the label_vars array into class variables
99  _geometry.d[0] = label_vals[0];
100  _geometry.n[0] = label_vals[1];
101  _geometry.min[0] = label_vals[6];
102 
103  _geometry.d[1] = label_vals[2];
104  _geometry.n[1] = label_vals[3];
105  _geometry.min[1] = label_vals[7];
106 
107  _geometry.d[2] = label_vals[4];
108  _geometry.n[2] = label_vals[5];
109  _geometry.min[2] = label_vals[8];
110 
111  unsigned int dim;
112 
113  // determine mesh dimension
114  for (dim = 3; dim > 0 && _geometry.n[dim - 1] == 0; --dim)
115  ;
116 
117  // check if the data has nonzero stepsizes
118  for (unsigned i = 0; i < dim; ++i)
119  {
120  if (_geometry.n[i] == 0)
121  mooseError("Error reading header, EBSD grid size is zero.");
122  if (_geometry.d[i] == 0.0)
123  mooseError("Error reading header, EBSD data step size is zero.");
124  }
125 
126  if (dim == 0)
127  mooseError("Error reading header, EBSD data is zero dimensional.");
128 
129  _geometry.dim = dim;
130 }
EBSDMeshGeometry _geometry
EBSD data file mesh information.
Definition: EBSDMesh.h:57
std::array< unsigned int, 3 > n
Definition: EBSDMesh.h:42
std::array< Real, 3 > d
Definition: EBSDMesh.h:36
std::string _filename
Name of the file containing the EBSD data.
Definition: EBSDMesh.h:54
std::array< Real, 3 > min
Definition: EBSDMesh.h:38

Member Data Documentation

◆ _filename

std::string EBSDMesh::_filename
protected

Name of the file containing the EBSD data.

Definition at line 54 of file EBSDMesh.h.

Referenced by getEBSDFilename(), and readEBSDHeader().

◆ _geometry

EBSDMeshGeometry EBSDMesh::_geometry
protected

EBSD data file mesh information.

Definition at line 57 of file EBSDMesh.h.

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


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