https://mooseframework.inl.gov
Loading...
Searching...
No Matches
EBSDMesh.C
Go to the documentation of this file.
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#include "EBSDMesh.h"
11#include "MooseApp.h"
12
13#include <fstream>
14
15registerMooseObject("PhaseFieldApp", EBSDMesh);
16
19{
21 params.addClassDescription("Mesh generated from a specified DREAM.3D EBSD data file.");
22 params.addRequiredParam<FileName>("filename", "The name of the file containing the EBSD data");
23 params.addParam<unsigned int>(
24 "uniform_refine", 0, "Number of coarsening levels available in adaptive mesh refinement.");
25
26 // suppress parameters
27 params.suppressParameter<MooseEnum>("dim");
28 params.set<MooseEnum>("dim") = MooseEnum("1=1 2 3", "1");
29 params.suppressParameter<unsigned int>("nx");
30 params.suppressParameter<unsigned int>("ny");
31 params.suppressParameter<unsigned int>("nz");
32 params.suppressParameter<Real>("xmin");
33 params.suppressParameter<Real>("ymin");
34 params.suppressParameter<Real>("zmin");
35 params.suppressParameter<Real>("xmax");
36 params.suppressParameter<Real>("ymax");
37 params.suppressParameter<Real>("zmax");
38
39 return params;
40}
41
43 : GeneratedMesh(parameters), _filename(getParam<FileName>("filename"))
44{
46 "EBSDMesh is deprecated, please use the EBSDMeshGenerator instead. For example:\n\n[Mesh]\n "
47 "type = EBDSMesh\n filename = my_ebsd_data.dat\n[]\n\nbecomes\n\n[Mesh]\n [ebsd_mesh]\n "
48 "type = EBDSMeshGenerator\n filename = my_ebsd_data.dat\n []\n[]");
49
50 if (_nx != 1 || _ny != 1 || _nz != 1)
51 mooseWarning("Do not specify mesh geometry information, it is read from the EBSD file.");
52}
53
55
56void
58{
59 std::ifstream stream_in(_filename.c_str());
60
61 if (!stream_in)
62 paramError("filename", "Can't open EBSD file: ", _filename);
63
64 // Labels to look for in the header
65 std::vector<std::string> labels = {
66 "x_step", "x_dim", "y_step", "y_dim", "z_step", "z_dim", "x_min", "y_min", "z_min"};
67
68 // Dimension variables to store once they are found in the header
69 // X_step, X_Dim, Y_step, Y_Dim, Z_step, Z_Dim
70 // We use Reals even though the Dim values should all be integers...
71 std::vector<Real> label_vals(labels.size(), 0.0);
72
73 std::string line;
74 while (std::getline(stream_in, line))
75 {
76 // We need to process the comment lines that have:
77 // X_step, X_Dim
78 // Y_step, Y_Dim
79 // Z_step, Z_Dim
80 // in them. The labels are case insensitive.
81 if (line.find("#") == 0)
82 {
83 // Process lines that start with a comment character (comments and meta data)
84 std::transform(line.begin(), line.end(), line.begin(), ::tolower);
85
86 for (unsigned i = 0; i < labels.size(); ++i)
87 if (line.find(labels[i]) != std::string::npos)
88 {
89 std::string dummy;
90 std::istringstream iss(line);
91 iss >> dummy >> dummy >> label_vals[i];
92
93 // One label per line, break out of for loop over labels
94 break;
95 }
96 }
97 else
98 // first non comment line marks the end of the header
99 break;
100 }
101
102 // Copy stuff out of the label_vars array into class variables
103 _geometry.d[0] = label_vals[0];
104 _geometry.n[0] = label_vals[1];
105 _geometry.min[0] = label_vals[6];
106
107 _geometry.d[1] = label_vals[2];
108 _geometry.n[1] = label_vals[3];
109 _geometry.min[1] = label_vals[7];
110
111 _geometry.d[2] = label_vals[4];
112 _geometry.n[2] = label_vals[5];
113 _geometry.min[2] = label_vals[8];
114
115 unsigned int dim;
116
117 // determine mesh dimension
118 for (dim = 3; dim > 0 && _geometry.n[dim - 1] == 0; --dim)
119 ;
120
121 // check if the data has nonzero stepsizes
122 for (unsigned i = 0; i < dim; ++i)
123 {
124 if (_geometry.n[i] == 0)
125 mooseError("Error reading header, EBSD grid size is zero.");
126 if (_geometry.d[i] == 0.0)
127 mooseError("Error reading header, EBSD data step size is zero.");
128 }
129
130 if (dim == 0)
131 mooseError("Error reading header, EBSD data is zero dimensional.");
132
133 _geometry.dim = dim;
134}
135
136void
138{
140
141 unsigned int uniform_refine = getParam<unsigned int>("uniform_refine");
142 _dim = (_geometry.dim == 1 ? "1" : (_geometry.dim == 2 ? "2" : "3"));
143
144 std::array<unsigned int, 3> nr;
145 nr[0] = _geometry.n[0];
146 nr[1] = _geometry.n[1];
147 nr[2] = _geometry.n[2];
148
149 // set min/max box length
150 _xmin = _geometry.min[0];
151 _xmax = nr[0] * _geometry.d[0] + _geometry.min[0];
152 _ymin = _geometry.min[1];
153 _ymax = nr[1] * _geometry.d[1] + _geometry.min[1];
154 _zmin = _geometry.min[2];
155 _zmax = nr[2] * _geometry.d[2] + _geometry.min[2];
156
157 // check if the requested uniform refine level is possible and determine initial grid size
158 for (unsigned int i = 0; i < uniform_refine; ++i)
159 for (unsigned int j = 0; j < _geometry.dim; ++j)
160 {
161 if (nr[j] % 2 != 0)
162 mooseError("EBSDMesh error. Requested uniform_refine levels not possible.");
163 nr[j] /= 2;
164 }
165
166 _nx = nr[0];
167 _ny = nr[1];
168 _nz = nr[2];
169
171}
registerMooseObject("PhaseFieldApp", EBSDMesh)
unsigned int dim
Mesh generated from parameters.
Definition EBSDMesh.h:21
virtual ~EBSDMesh()
Definition EBSDMesh.C:54
std::string _filename
Name of the file containing the EBSD data.
Definition EBSDMesh.h:51
static InputParameters validParams()
Definition EBSDMesh.C:18
EBSDMeshGenerator::Geometry _geometry
EBSD data file mesh information.
Definition EBSDMesh.h:54
virtual void buildMesh()
Definition EBSDMesh.C:137
void readEBSDHeader()
Read the EBSD data file header.
Definition EBSDMesh.C:57
EBSDMesh(const InputParameters &parameters)
Definition EBSDMesh.C:42
unsigned int _nz
unsigned int _nx
MooseEnum _dim
virtual void buildMesh() override
static InputParameters validParams()
unsigned int _ny
void suppressParameter(const std::string &name)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
void mooseDeprecated(Args &&... args) const
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
void mooseWarning(Args &&... args) const
std::array< Real, 3 > min
std::array< unsigned int, 3 > n