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