LCOV - code coverage report
Current view: top level - src/actioncomponents - WellBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #32971 (54bef8) with base c6cf66 Lines: 105 115 91.3 %
Date: 2026-05-29 20:41:18 Functions: 9 10 90.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       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 "WellBase.h"
      11             : #include "PhysicalConstants.h"
      12             : 
      13             : InputParameters
      14          18 : WellBase::validParams()
      15             : {
      16          18 :   InputParameters params = THMActionComponent::validParams();
      17             : 
      18          36 :   params.addRequiredParam<Point>("surface_point", "Surface point [m]");
      19          36 :   params.addRequiredParam<std::vector<Point>>("junction_points", "Junction points [m]");
      20          36 :   params.addParam<Point>(
      21             :       "end_point", "End point [m]. If not provided, the well ends at the final volume junction");
      22          36 :   params.addRequiredParam<std::vector<unsigned int>>("section_n_elems",
      23             :                                                      "Number of elements in each well section");
      24          36 :   params.addRequiredParam<FunctionName>("area",
      25             :                                         "Cross-sectional flow area function of the well [m^2]");
      26          36 :   params.addRequiredParam<std::vector<Real>>("junction_coupling_areas",
      27             :                                              "Flow surface area for each junction point [m^2]");
      28          36 :   params.addRequiredParam<RealVectorValue>("fracture_direction", "Direction to fracture");
      29          36 :   params.addRequiredParam<Real>("junction_volume", "Volume of each junction [m^3]");
      30             : 
      31          36 :   params.addRequiredParam<FunctionName>("initial_pressure", "Initial pressure function [Pa]");
      32          36 :   params.addRequiredParam<FunctionName>("initial_temperature", "Initial temperature function [K]");
      33             : 
      34          36 :   params.addRequiredParam<UserObjectName>("fluid_properties", "Fluid properties object");
      35          36 :   params.addParam<FunctionName>("friction_factor", "0.0", "Darcy friction factor function");
      36             : 
      37          36 :   params.addParam<MultiAppName>(
      38             :       "multi_app",
      39             :       "If provided, transfers occur with this MultiApp. The following would be transferred: mass "
      40             :       "flow rate, energy flow rate, temperature, and pressure at each junction.");
      41             : 
      42          18 :   return params;
      43           0 : }
      44             : 
      45          18 : WellBase::WellBase(const InputParameters & params)
      46             :   : THMActionComponent(params),
      47          18 :     _surface_point(getParam<Point>("surface_point")),
      48          36 :     _junction_points(getParam<std::vector<Point>>("junction_points")),
      49          36 :     _section_n_elems(getParam<std::vector<unsigned int>>("section_n_elems")),
      50          18 :     _n_sections(_section_n_elems.size()),
      51          36 :     _junction_coupling_areas(getParam<std::vector<Real>>("junction_coupling_areas")),
      52          36 :     _closures_name(name() + "_closures")
      53             : {
      54          18 :   _all_points.push_back(_surface_point);
      55          54 :   for (const auto i : index_range(_junction_points))
      56          36 :     _all_points.push_back(_junction_points[i]);
      57          36 :   if (isParamValid("end_point"))
      58           0 :     _all_points.push_back(getParam<Point>("end_point"));
      59             : 
      60          36 :   checkVectorParamsSameLength<Point, unsigned int>("junction_points", "section_n_elems");
      61          36 :   checkVectorParamsSameLength<Point, Real>("junction_points", "junction_coupling_areas");
      62          18 : }
      63             : 
      64             : void
      65          18 : WellBase::addClosures()
      66             : {
      67          18 :   const std::string class_name = "Closures1PhaseSimple";
      68          18 :   auto params = _factory.getValidParams(class_name);
      69          18 :   addClosuresObject(class_name, _closures_name, params);
      70          36 : }
      71             : 
      72             : void
      73          18 : WellBase::addWellBaseComponents(bool is_production)
      74             : {
      75          72 :   for (const auto i : index_range(_all_points))
      76          54 :     if (i != 0)
      77          36 :       addFlowChannel(i - 1, is_production);
      78             : 
      79          36 :   if (isParamValid("end_point"))
      80           0 :     addWall(is_production);
      81             : 
      82          54 :   for (const auto i : index_range(_junction_points))
      83             :   {
      84          36 :     addJunction(i, is_production);
      85          36 :     addJunctionFlux(i);
      86             :   }
      87          18 : }
      88             : 
      89             : void
      90          36 : WellBase::addFlowChannel(unsigned int i, bool is_production)
      91             : {
      92             :   Point start_position, end_position;
      93          36 :   if (is_production)
      94             :   {
      95          18 :     start_position = _all_points[i + 1];
      96          18 :     end_position = _all_points[i];
      97             :   }
      98             :   else
      99             :   {
     100          18 :     start_position = _all_points[i];
     101          18 :     end_position = _all_points[i + 1];
     102             :   }
     103             : 
     104             :   const RealVectorValue translation = end_position - start_position;
     105             : 
     106          36 :   const std::string class_name = "FlowChannel1Phase";
     107          36 :   auto params = _factory.getValidParams(class_name);
     108          36 :   params.set<Point>("position") = start_position;
     109          36 :   params.set<RealVectorValue>("orientation") = translation;
     110          36 :   params.set<std::vector<Real>>("length") = {translation.norm()};
     111          36 :   params.set<std::vector<unsigned int>>("n_elems") = {_section_n_elems[i]};
     112         108 :   params.set<FunctionName>("A") = getParam<FunctionName>("area");
     113         108 :   params.set<FunctionName>("initial_p") = getParam<FunctionName>("initial_pressure");
     114         108 :   params.set<FunctionName>("initial_T") = getParam<FunctionName>("initial_temperature");
     115          72 :   params.set<FunctionName>("initial_vel") = "0.0";
     116          36 :   params.set<RealVectorValue>("gravity_vector") = {
     117             :       0, 0, -PhysicalConstants::acceleration_of_gravity};
     118         108 :   params.set<UserObjectName>("fp") = getParam<UserObjectName>("fluid_properties");
     119         108 :   params.set<std::vector<std::string>>("closures") = {_closures_name};
     120         108 :   params.set<FunctionName>("f") = getParam<FunctionName>("friction_factor");
     121          72 :   params.set<MooseEnum>("rdg_slope_reconstruction") = "full";
     122          72 :   params.set<std::vector<Real>>("scaling_factor_1phase") = {1.0, 1.0, 1e-5};
     123         108 :   params.set<std::vector<VariableName>>("vpp_vars") = {"p"};
     124          36 :   params.set<bool>("create_flux_vpp") = true;
     125          36 :   addTHMComponent(class_name, flowChannelName(i), params);
     126         108 : }
     127             : 
     128             : void
     129           0 : WellBase::addWall(bool is_production)
     130             : {
     131           0 :   const std::string in_or_out = is_production ? ":in" : ":out";
     132             : 
     133           0 :   const std::string class_name = "SolidWall1Phase";
     134           0 :   auto params = _factory.getValidParams(class_name);
     135           0 :   params.set<BoundaryName>("input") = flowChannelName(_n_sections - 1) + in_or_out;
     136           0 :   addTHMComponent(class_name, name() + "_wall", params);
     137           0 : }
     138             : 
     139             : void
     140          36 : WellBase::addJunction(unsigned int i, bool is_production)
     141             : {
     142          54 :   const std::string first_end = is_production ? ":in" : ":out";
     143          54 :   const std::string second_end = is_production ? ":out" : ":in";
     144             :   std::vector<BoundaryName> connections;
     145          36 :   connections.push_back(flowChannelName(i) + first_end);
     146          36 :   if (i + 1 <= _n_sections - 1)
     147          36 :     connections.push_back(flowChannelName(i + 1) + second_end);
     148             : 
     149          36 :   const std::string class_name = "VolumeJunction1Phase";
     150          36 :   auto params = _factory.getValidParams(class_name);
     151          36 :   params.set<Point>("position") = _junction_points[i];
     152          36 :   params.set<std::vector<BoundaryName>>("connections") = connections;
     153         108 :   params.set<FunctionName>("initial_p") = getParam<FunctionName>("initial_pressure");
     154         108 :   params.set<FunctionName>("initial_T") = getParam<FunctionName>("initial_temperature");
     155          72 :   params.set<FunctionName>("initial_vel_x") = "0.0";
     156          72 :   params.set<FunctionName>("initial_vel_y") = "0.0";
     157          72 :   params.set<FunctionName>("initial_vel_z") = "0.0";
     158          72 :   params.set<Real>("volume") = getParam<Real>("junction_volume");
     159          36 :   params.set<Real>("scaling_factor_rhoEV") = 1e-5;
     160          36 :   addTHMComponent(class_name, volumeJunctionName(i), params);
     161         108 : }
     162             : 
     163             : void
     164          36 : WellBase::addJunctionFlux(unsigned int i)
     165             : {
     166          36 :   const std::string class_name = "VolumeJunctionCoupledFlux1Phase";
     167          36 :   auto params = _factory.getValidParams(class_name);
     168          36 :   params.set<Real>("A_coupled") = _junction_coupling_areas[i];
     169          36 :   params.set<RealVectorValue>("normal_from_junction") =
     170          36 :       getParam<RealVectorValue>("fracture_direction");
     171          72 :   params.set<std::string>("volume_junction") = volumeJunctionName(i);
     172          72 :   params.set<std::string>("pp_suffix") = name() + std::to_string(i + 1);
     173          72 :   if (isParamValid("multi_app"))
     174         108 :     params.set<MultiAppName>("multi_app") = getParam<MultiAppName>("multi_app");
     175          72 :   addTHMComponent(class_name, volumeJunctionName(i) + "_flux", params);
     176          72 : }
     177             : 
     178             : std::string
     179         108 : WellBase::flowChannelName(unsigned int i) const
     180             : {
     181         216 :   return name() + std::to_string(i + 1);
     182             : }
     183             : 
     184             : std::string
     185         108 : WellBase::volumeJunctionName(unsigned int i) const
     186             : {
     187         216 :   return name() + "_junc" + std::to_string(i + 1);
     188             : }

Generated by: LCOV version 1.14