www.mooseframework.org
RichardsPolyLineSink.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 
8 #include "RichardsPolyLineSink.h"
9 
10 #include <fstream>
11 
12 template <>
13 InputParameters
15 {
16  InputParameters params = validParams<DiracKernel>();
17  params.addRequiredParam<std::vector<Real>>(
18  "pressures", "Tuple of pressure values. Must be monotonically increasing.");
19  params.addRequiredParam<std::vector<Real>>(
20  "fluxes",
21  "Tuple of flux values (measured in kg.m^-3.s^-1). A piecewise-linear fit is "
22  "performed to the (pressure,flux) pairs to obtain the flux at any arbitrary "
23  "pressure. If a quad-point pressure is less than the first pressure value, the "
24  "first flux value is used. If quad-point pressure exceeds the final pressure "
25  "value, the final flux value is used. This flux is OUT of the medium: hence "
26  "positive values of flux means this will be a SINK, while negative values indicate "
27  "this flux will be a SOURCE.");
28  params.addRequiredParam<FileName>(
29  "point_file",
30  "The file containing the coordinates of the point sinks that will approximate "
31  "the polyline. Each line in the file must contain a space-separated "
32  "coordinate. Note that you will get segementation faults if your points do "
33  "not lie within your mesh!");
34  params.addRequiredParam<UserObjectName>(
35  "SumQuantityUO",
36  "User Object of type=RichardsSumQuantity in which to place the total "
37  "outflow from the polylinesink for each time step.");
38  params.addRequiredParam<UserObjectName>(
39  "richardsVarNames_UO", "The UserObject that holds the list of Richards variable names.");
40  params.addClassDescription("Approximates a polyline sink in the mesh by using a number of point "
41  "sinks whose positions are read from a file");
42  return params;
43 }
44 
45 RichardsPolyLineSink::RichardsPolyLineSink(const InputParameters & parameters)
46  : DiracKernel(parameters),
47  _total_outflow_mass(
48  const_cast<RichardsSumQuantity &>(getUserObject<RichardsSumQuantity>("SumQuantityUO"))),
49  _sink_func(getParam<std::vector<Real>>("pressures"), getParam<std::vector<Real>>("fluxes")),
50  _point_file(getParam<FileName>("point_file")),
51  _richards_name_UO(getUserObject<RichardsVarNames>("richardsVarNames_UO")),
52  _pvar(_richards_name_UO.richards_var_num(_var.number())),
53  _pp(getMaterialProperty<std::vector<Real>>("porepressure")),
54  _dpp_dv(getMaterialProperty<std::vector<std::vector<Real>>>("dporepressure_dv"))
55 {
56  // open file
57  std::ifstream file(_point_file.c_str());
58  if (!file.good())
59  mooseError("Error opening file '" + _point_file + "' from RichardsPolyLineSink.");
60 
61  std::vector<Real> scratch;
62  while (parseNextLineReals(file, scratch))
63  {
64  if (scratch.size() >= 1)
65  {
66  _xs.push_back(scratch[0]);
67  if (scratch.size() >= 2)
68  _ys.push_back(scratch[1]);
69  else
70  _ys.push_back(0.0);
71 
72  if (scratch.size() >= 3)
73  _zs.push_back(scratch[2]);
74  else
75  _zs.push_back(0.0);
76  }
77  }
78 
79  file.close();
80 
81  // To correctly compute the Jacobian terms,
82  // tell MOOSE that this DiracKernel depends on all the Richards Vars
83  const std::vector<MooseVariable *> & coupled_vars = _richards_name_UO.getCoupledMooseVars();
84  for (unsigned int i = 0; i < coupled_vars.size(); i++)
85  addMooseVariableDependency(coupled_vars[i]);
86 }
87 
88 bool
89 RichardsPolyLineSink::parseNextLineReals(std::ifstream & ifs, std::vector<Real> & myvec)
90 // reads a space-separated line of floats from ifs and puts in myvec
91 {
92  std::string line;
93  myvec.clear();
94  bool gotline(false);
95  if (getline(ifs, line))
96  {
97  gotline = true;
98 
99  // Harvest floats separated by whitespace
100  std::istringstream iss(line);
101  Real f;
102  while (iss >> f)
103  {
104  myvec.push_back(f);
105  }
106  }
107  return gotline;
108 }
109 
110 void
112 {
114 
115  // Add point using the unique ID "i", let the DiracKernel take
116  // care of the caching. This should be fast after the first call,
117  // as long as the points don't move around.
118  for (unsigned int i = 0; i < _zs.size(); i++)
119  addPoint(Point(_xs[i], _ys[i], _zs[i]), i);
120 }
121 
122 Real
124 {
125  Real test_fcn = _test[_i][_qp];
126  Real flow = test_fcn * _sink_func.sample(_pp[_qp][_pvar]);
127  _total_outflow_mass.add(flow * _dt);
128  return flow;
129 }
130 
131 Real
133 {
134  Real test_fcn = _test[_i][_qp];
135  return test_fcn * _sink_func.sampleDerivative(_pp[_qp][_pvar]) * _dpp_dv[_qp][_pvar][_pvar] *
136  _phi[_j][_qp];
137 }
138 
139 Real
141 {
143  return 0.0;
144  unsigned int dvar = _richards_name_UO.richards_var_num(jvar);
145  Real test_fcn = _test[_i][_qp];
146  return test_fcn * _sink_func.sampleDerivative(_pp[_qp][_pvar]) * _dpp_dv[_qp][_pvar][dvar] *
147  _phi[_j][_qp];
148 }
Sums into _total This is used, for instance, to record the total mass flowing into a borehole...
virtual Real computeQpResidual()
std::string _point_file
contains rows of the form x y z (space separated)
bool not_richards_var(unsigned int moose_var_num) const
returns true if moose_var_num is not a richards var
std::vector< Real > _ys
vector of Dirac Points&#39; y positions
InputParameters validParams< RichardsPolyLineSink >()
This holds maps between pressure_var or pressure_var, sat_var used in RichardsMaterial and kernels...
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Computes the off-diagonal part of the jacobian Note: at March2014 this is never called since moose do...
RichardsPolyLineSink(const InputParameters &parameters)
LinearInterpolation _sink_func
mass flux = _sink_func as a function of porepressure
virtual Real computeQpJacobian()
void zero()
sets _total = 0
unsigned int _pvar
The moose internal variable number of the richards variable of this Dirac Kernel. ...
bool parseNextLineReals(std::ifstream &ifs, std::vector< Real > &myvec)
reads a space-separated line of floats from ifs and puts in myvec
RichardsSumQuantity & _total_outflow_mass
This is used to hold the total fluid flowing into the sink Hence, it is positive for sinks where flui...
void add(Real contrib)
adds contrib to _total
const MaterialProperty< std::vector< Real > > & _pp
fluid porepressure (or porepressures in case of multiphase)
const MaterialProperty< std::vector< std::vector< Real > > > & _dpp_dv
d(porepressure_i)/d(variable_j)
std::vector< Real > _xs
vector of Dirac Points&#39; x positions
std::vector< Real > _zs
vector of Dirac Points&#39; z positions
const RichardsVarNames & _richards_name_UO
Defines the richards variables in the simulation.
unsigned int richards_var_num(unsigned int moose_var_num) const
the richards variable number