LCOV - code coverage report
Current view: top level - src/dirackernels - PorousFlowLineGeometry.C (source / functions) Hit Total Coverage
Test: porous_flow Test Coverage Lines: 54 55 98.2 %
Date: 2017-11-21 14:47:27 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "PorousFlowLineGeometry.h"
       9             : #include "libmesh/utility.h"
      10             : 
      11             : #include <fstream>
      12             : 
      13             : template <>
      14             : InputParameters
      15          62 : validParams<PorousFlowLineGeometry>()
      16             : {
      17          62 :   InputParameters params = validParams<DiracKernel>();
      18         186 :   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          62 :       "that you will get segementation faults if your points do not lie within your mesh!");
      27         248 :   params.addRangeCheckedParam<Real>(
      28             :       "line_length",
      29             :       0.0,
      30             :       "line_length>=0",
      31          62 :       "Line length.  Note this is only used if there is only one point in the point_file.");
      32         248 :   params.addParam<RealVectorValue>(
      33             :       "line_direction",
      34          62 :       RealVectorValue(0.0, 0.0, 1.0),
      35          62 :       "Line direction.  Note this is only used if there is only one point in the point_file.");
      36         124 :   params.addClassDescription("Approximates a polyline sink in the mesh using a number of Dirac "
      37          62 :                              "point sinks with given weightings that are read from a file");
      38          62 :   return params;
      39             : }
      40             : 
      41          62 : PorousFlowLineGeometry::PorousFlowLineGeometry(const InputParameters & parameters)
      42             :   : DiracKernel(parameters),
      43         186 :     _line_length(getParam<Real>("line_length")),
      44         124 :     _line_direction(getParam<RealVectorValue>("line_direction")),
      45         620 :     _point_file(getParam<std::string>("point_file"))
      46             : {
      47          62 :   statefulPropertiesAllowed(true);
      48             : 
      49             :   // open file
      50         122 :   std::ifstream file(_point_file.c_str());
      51          62 :   if (!file.good())
      52           1 :     mooseError("PorousFlowLineGeometry: Error opening file " + _point_file);
      53             : 
      54             :   // construct the arrays of weight, x, y and z
      55             :   std::vector<Real> scratch;
      56         189 :   while (parseNextLineReals(file, scratch))
      57             :   {
      58         128 :     if (scratch.size() >= 2)
      59             :     {
      60         107 :       _rs.push_back(scratch[0]);
      61         107 :       _xs.push_back(scratch[1]);
      62         107 :       if (scratch.size() >= 3)
      63         107 :         _ys.push_back(scratch[2]);
      64             :       else
      65           0 :         _ys.push_back(0.0);
      66         107 :       if (scratch.size() >= 4)
      67          74 :         _zs.push_back(scratch[3]);
      68             :       else
      69          66 :         _zs.push_back(0.0);
      70             :     }
      71             :   }
      72             : 
      73          61 :   file.close();
      74             : 
      75          61 :   const int num_pts = _zs.size();
      76         122 :   _bottom_point(0) = _xs[num_pts - 1];
      77          61 :   _bottom_point(1) = _ys[num_pts - 1];
      78          61 :   _bottom_point(2) = _zs[num_pts - 1];
      79             : 
      80             :   // construct the line-segment lengths between each point
      81         122 :   _half_seg_len.resize(std::max(num_pts - 1, 1));
      82         212 :   for (unsigned int i = 0; i + 1 < _xs.size(); ++i)
      83             :   {
      84         230 :     _half_seg_len[i] = 0.5 * std::sqrt(Utility::pow<2>(_xs[i + 1] - _xs[i]) +
      85          92 :                                        Utility::pow<2>(_ys[i + 1] - _ys[i]) +
      86          92 :                                        Utility::pow<2>(_zs[i + 1] - _zs[i]));
      87          46 :     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           1 :                  "\n");
      95             :   }
      96          60 :   if (num_pts == 1)
      97          33 :     _half_seg_len[0] = _line_length;
      98          60 : }
      99             : 
     100             : bool
     101         189 : 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         378 :   if (getline(ifs, line))
     108             :   {
     109             :     gotline = true;
     110             : 
     111             :     // Harvest floats separated by whitespace
     112         256 :     std::istringstream iss(line);
     113             :     Real f;
     114        1046 :     while (iss >> f)
     115             :     {
     116         395 :       myvec.push_back(f);
     117             :     }
     118             :   }
     119         189 :   return gotline;
     120             : }
     121             : 
     122             : void
     123        7641 : PorousFlowLineGeometry::addPoints()
     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       57204 :   for (unsigned int i = 0; i < _zs.size(); i++)
     129       55896 :     addPoint(Point(_xs[i], _ys[i], _zs[i]), i);
     130       10140 : }

Generated by: LCOV version 1.11