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