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 22 of file EBSDMesh.h.

Constructor & Destructor Documentation

EBSDMesh::EBSDMesh ( const InputParameters &  parameters)

Definition at line 38 of file EBSDMesh.C.

39  : GeneratedMesh(parameters), _filename(getParam<FileName>("filename"))
40 {
41  if (_nx != 1 || _ny != 1 || _nz != 1)
42  mooseWarning("Do not specify mesh geometry information, it is read from the EBSD file.");
43 }
std::string _filename
Name of the file containing the EBSD data.
Definition: EBSDMesh.h:51
EBSDMesh::~EBSDMesh ( )
virtual

Definition at line 45 of file EBSDMesh.C.

45 {}

Member Function Documentation

void EBSDMesh::buildMesh ( )
virtual

Definition at line 128 of file EBSDMesh.C.

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

Definition at line 44 of file EBSDMesh.h.

Referenced by EBSDReader::readFile().

44 { return _filename; }
std::string _filename
Name of the file containing the EBSD data.
Definition: EBSDMesh.h:51
const EBSDMeshGeometry& EBSDMesh::getEBSDGeometry ( ) const
inline

Definition at line 43 of file EBSDMesh.h.

Referenced by EBSDReader::readFile().

43 { return _geometry; }
EBSDMeshGeometry _geometry
EBSD data file mesh information.
Definition: EBSDMesh.h:54
void EBSDMesh::readEBSDHeader ( )
protected

Read the EBSD data file header.

Definition at line 48 of file EBSDMesh.C.

Referenced by buildMesh(), and getEBSDFilename().

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

Member Data Documentation

std::string EBSDMesh::_filename
protected

Name of the file containing the EBSD data.

Definition at line 51 of file EBSDMesh.h.

Referenced by getEBSDFilename(), and readEBSDHeader().

EBSDMeshGeometry EBSDMesh::_geometry
protected

EBSD data file mesh information.

Definition at line 54 of file EBSDMesh.h.

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


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