https://mooseframework.inl.gov
SmoothCircleFromFileIC.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 "SmoothCircleFromFileIC.h"
11 
13 
16 {
18  params.addClassDescription("Multiple smooth circles read from a text file");
19  params.addRequiredParam<FileName>("file_name", "File containing circle centers and radii");
20 
21  return params;
22 }
23 
25  : SmoothCircleBaseIC(parameters),
26  _data(0),
27  _file_name(getParam<FileName>("file_name")),
28  _txt_reader(_file_name, &_communicator),
29  _n_circles(0)
30 {
31  // Read names and vectors from file
32  _txt_reader.read();
35  _n_circles = _data[0].size();
36 
37  // Check that the file has all the correct information
38  for (unsigned int i = 0; i < _col_names.size(); ++i)
39  {
40  // Check that columns have uniform lengths
41  if (_data[i].size() != _n_circles)
42  mooseError("Columns in ", _file_name, " do not have uniform lengths.");
43 
44  // Determine which columns correspond to which parameters.
45  if (_col_names[i] == "x")
46  _col_map[X] = i;
47  else if (_col_names[i] == "y")
48  _col_map[Y] = i;
49  else if (_col_names[i] == "z")
50  _col_map[Z] = i;
51  else if (_col_names[i] == "r")
52  _col_map[R] = i;
53  }
54 
55  // Check that the required columns are present
56  if (_col_map[X] == -1)
57  mooseError("No column in ", _file_name, " labeled 'x'.");
58  if (_col_map[Y] == -1)
59  mooseError("No column in ", _file_name, " labeled 'y'.");
60  if (_col_map[Z] == -1)
61  mooseError("No column in ", _file_name, " labeled 'z'.");
62  if (_col_map[R] == -1)
63  mooseError("No column in ", _file_name, " labeled 'r'.");
64 }
65 
66 void
68 {
69  _radii.assign(_data[_col_map[R]].begin(), _data[_col_map[R]].end());
70 }
71 
72 void
74 {
75  _centers.resize(_n_circles);
76  for (unsigned int i = 0; i < _n_circles; ++i)
77  {
78  _centers[i](0) = _data[_col_map[X]][i];
79  _centers[i](1) = _data[_col_map[Y]][i];
80  _centers[i](2) = _data[_col_map[Z]][i];
81  }
82 }
static InputParameters validParams()
std::vector< Real > _radii
static InputParameters validParams()
std::vector< Point > _centers
void addRequiredParam(const std::string &name, const std::string &doc_string)
SmoothcircleBaseIC is the base class for all initial conditions that create circles.
MooseUtils::DelimitedFileReader _txt_reader
std::vector< std::string > _col_names
SmoothCircleFromFileIC(const InputParameters &parameters)
Reads multiple circles from a text file with the columns labeled x y z r.
const std::vector< std::vector< T > > & getData() const
std::array< int, 4 > _col_map
registerMooseObject("PhaseFieldApp", SmoothCircleFromFileIC)
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
const std::vector< std::string > & getNames() const
std::vector< std::vector< Real > > _data