www.mooseframework.org
PorousFlowLineGeometry.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 /****************************************************************/
7 
9 #include "libmesh/utility.h"
10 
11 #include <fstream>
12 
13 template <>
14 InputParameters
16 {
17  InputParameters params = validParams<DiracKernel>();
18  params.addRequiredParam<std::string>(
19  "point_file",
20  "The file containing the coordinates of the points and their weightings that approximate the "
21  "line sink. The physical meaning of the weightings depend on the scenario, eg, they may be "
22  "borehole radii. Each line in the file must contain a space-separated weight and "
23  "coordinate, viz r x y z. For boreholes, the last point in the file is defined as the "
24  "borehole bottom, where the borehole pressure is bottom_pressure. If your file contains "
25  "just one point, you must also specify the line_length and line_direction parameters. Note "
26  "that you will get segementation faults if your points do not lie within your mesh!");
27  params.addRangeCheckedParam<Real>(
28  "line_length",
29  0.0,
30  "line_length>=0",
31  "Line length. Note this is only used if there is only one point in the point_file.");
32  params.addParam<RealVectorValue>(
33  "line_direction",
34  RealVectorValue(0.0, 0.0, 1.0),
35  "Line direction. Note this is only used if there is only one point in the point_file.");
36  params.addClassDescription("Approximates a polyline sink in the mesh using a number of Dirac "
37  "point sinks with given weightings that are read from a file");
38  return params;
39 }
40 
41 PorousFlowLineGeometry::PorousFlowLineGeometry(const InputParameters & parameters)
42  : DiracKernel(parameters),
43  _line_length(getParam<Real>("line_length")),
44  _line_direction(getParam<RealVectorValue>("line_direction")),
45  _point_file(getParam<std::string>("point_file"))
46 {
47  statefulPropertiesAllowed(true);
48 
49  // open file
50  std::ifstream file(_point_file.c_str());
51  if (!file.good())
52  mooseError("PorousFlowLineGeometry: Error opening file " + _point_file);
53 
54  // construct the arrays of weight, x, y and z
55  std::vector<Real> scratch;
56  while (parseNextLineReals(file, scratch))
57  {
58  if (scratch.size() >= 2)
59  {
60  _rs.push_back(scratch[0]);
61  _xs.push_back(scratch[1]);
62  if (scratch.size() >= 3)
63  _ys.push_back(scratch[2]);
64  else
65  _ys.push_back(0.0);
66  if (scratch.size() >= 4)
67  _zs.push_back(scratch[3]);
68  else
69  _zs.push_back(0.0);
70  }
71  }
72 
73  file.close();
74 
75  const int num_pts = _zs.size();
76  _bottom_point(0) = _xs[num_pts - 1];
77  _bottom_point(1) = _ys[num_pts - 1];
78  _bottom_point(2) = _zs[num_pts - 1];
79 
80  // construct the line-segment lengths between each point
81  _half_seg_len.resize(std::max(num_pts - 1, 1));
82  for (unsigned int i = 0; i + 1 < _xs.size(); ++i)
83  {
84  _half_seg_len[i] = 0.5 * std::sqrt(Utility::pow<2>(_xs[i + 1] - _xs[i]) +
85  Utility::pow<2>(_ys[i + 1] - _ys[i]) +
86  Utility::pow<2>(_zs[i + 1] - _zs[i]));
87  if (_half_seg_len[i] == 0)
88  mooseError("PorousFlowLineGeometry: zero-segment length detected at (x,y,z) = ",
89  _xs[i],
90  " ",
91  _ys[i],
92  " ",
93  _zs[i],
94  "\n");
95  }
96  if (num_pts == 1)
98 }
99 
100 bool
101 PorousFlowLineGeometry::parseNextLineReals(std::ifstream & ifs, std::vector<Real> & myvec)
102 // reads a space-separated line of floats from ifs and puts in myvec
103 {
104  std::string line;
105  myvec.clear();
106  bool gotline(false);
107  if (getline(ifs, line))
108  {
109  gotline = true;
110 
111  // Harvest floats separated by whitespace
112  std::istringstream iss(line);
113  Real f;
114  while (iss >> f)
115  {
116  myvec.push_back(f);
117  }
118  }
119  return gotline;
120 }
121 
122 void
124 {
125  // Add point using the unique ID "i", let the DiracKernel take
126  // care of the caching. This should be fast after the first call,
127  // as long as the points don't move around.
128  for (unsigned int i = 0; i < _zs.size(); i++)
129  addPoint(Point(_xs[i], _ys[i], _zs[i]), i);
130 }
virtual void addPoints() override
Add Dirac Points to the line sink.
bool parseNextLineReals(std::ifstream &ifs, std::vector< Real > &myvec)
reads a space-separated line of floats from ifs and puts in myvec
const Real _line_length
line length. This is only used if there is only one borehole point
std::vector< Real > _ys
y points of the borehole
std::vector< Real > _half_seg_len
0.5*(length of polyline segments between points)
PorousFlowLineGeometry(const InputParameters &parameters)
Creates a new PorousFlowLineGeometry This reads the file containing the lines of the form weight x y ...
std::vector< Real > _zs
z points of borehole
const std::string _point_file
File defining the geometry of the borehole.
std::vector< Real > _xs
x points of the borehole
std::vector< Real > _rs
radii of the borehole
Point _bottom_point
the bottom point of the borehole (where bottom_pressure is defined)
InputParameters validParams< PorousFlowLineGeometry >()