www.mooseframework.org
SmoothCircleFromFileIC.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
8 
9 template <>
10 InputParameters
12 {
13  InputParameters params = validParams<SmoothCircleBaseIC>();
14  params.addClassDescription("Multiple smooth circles read from a text file");
15  params.addRequiredParam<FileName>("file_name", "File containing circle centers and radii");
16 
17  return params;
18 }
19 
20 SmoothCircleFromFileIC::SmoothCircleFromFileIC(const InputParameters & parameters)
21  : SmoothCircleBaseIC(parameters),
22  _data(0),
23  _file_name(getParam<FileName>("file_name")),
24  _txt_reader(_file_name, &_communicator),
25  _n_circles(0)
26 {
27  // Read names and vectors from file
28  _txt_reader.read();
29  _col_names = _txt_reader.getNames();
30  _data = _txt_reader.getData();
31  _n_circles = _data[0].size();
32 
33  // Check that the file has all the correct information
34  for (unsigned int i = 0; i < _col_names.size(); ++i)
35  {
36  // Check that columns have uniform lengths
37  if (_data[i].size() != _n_circles)
38  mooseError("Columns in ", _file_name, " do not have uniform lengths.");
39 
40  // Determine which columns correspond to which parameters.
41  if (_col_names[i] == "x")
42  _col_map[X] = i;
43  else if (_col_names[i] == "y")
44  _col_map[Y] = i;
45  else if (_col_names[i] == "z")
46  _col_map[Z] = i;
47  else if (_col_names[i] == "r")
48  _col_map[R] = i;
49  }
50 
51  // Check that the required columns are present
52  if (_col_map[X] == -1)
53  mooseError("No column in ", _file_name, " labeled 'x'.");
54  if (_col_map[Y] == -1)
55  mooseError("No column in ", _file_name, " labeled 'y'.");
56  if (_col_map[Z] == -1)
57  mooseError("No column in ", _file_name, " labeled 'z'.");
58  if (_col_map[R] == -1)
59  mooseError("No column in ", _file_name, " labeled 'r'.");
60 }
61 
62 void
64 {
65  _radii.assign(_data[_col_map[R]].begin(), _data[_col_map[R]].end());
66 }
67 
68 void
70 {
71  _centers.resize(_n_circles);
72  for (unsigned int i = 0; i < _n_circles; ++i)
73  {
74  _centers[i](0) = _data[_col_map[X]][i];
75  _centers[i](1) = _data[_col_map[Y]][i];
76  _centers[i](2) = _data[_col_map[Z]][i];
77  }
78 }
std::vector< Real > _radii
std::vector< Point > _centers
SmoothcircleBaseIC is the base class for all initial conditions that create circles.
MooseUtils::DelimitedFileReader _txt_reader
std::vector< std::string > _col_names
InputParameters validParams< SmoothCircleBaseIC >()
InputParameters validParams< SmoothCircleFromFileIC >()
SmoothCircleFromFileIC(const InputParameters &parameters)
std::array< int, 4 > _col_map
std::vector< std::vector< Real > > _data