LCOV - code coverage report
Current view: top level - src/userobjects - InterfaceQpUserObjectBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 37 52 71.2 %
Date: 2025-07-17 01:28:37 Functions: 5 6 83.3 %
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 "InterfaceQpUserObjectBase.h"
      11             : 
      12             : InputParameters
      13       28985 : InterfaceQpUserObjectBase::validParams()
      14             : {
      15       28985 :   InputParameters params = InterfaceValueUserObject::validParams();
      16       28985 :   params.addClassDescription("Base class to compute a scalar value or rate across an interface");
      17       86955 :   params.addParam<MooseEnum>("value_type",
      18       57970 :                              InterfaceQpUserObjectBase::valueOptions(),
      19             :                              "Type of value to compute and store");
      20       86955 :   params.set<ExecFlagEnum>("execute_on", true) = {EXEC_INITIAL, EXEC_TIMESTEP_END};
      21       28985 :   return params;
      22       28985 : }
      23             : 
      24         231 : InterfaceQpUserObjectBase::InterfaceQpUserObjectBase(const InputParameters & parameters)
      25         231 :   : InterfaceValueUserObject(parameters), _value_type(getParam<MooseEnum>("value_type"))
      26             : 
      27             : {
      28         231 : }
      29             : 
      30             : void
      31         231 : InterfaceQpUserObjectBase::initialSetup()
      32             : {
      33             :   // define the boundary map and retrieve element side and boundary_ID
      34             :   std::vector<std::tuple<dof_id_type, unsigned short int, boundary_id_type>> elem_side_bid =
      35         231 :       _mesh.buildSideList();
      36             : 
      37             :   // retrieve on which boundary this UO operates
      38         231 :   std::set<BoundaryID> boundaryList = boundaryIDs();
      39             : 
      40             :   // initialize the map_values looping over all the element and sides
      41        5561 :   for (unsigned int i = 0; i < elem_side_bid.size(); i++)
      42             :   {
      43             :     // check if this element side is part of the boundary, if so add element side to the interface
      44             :     // map
      45        5330 :     if (boundaryList.find(std::get<2>(elem_side_bid[i])) != boundaryList.end())
      46             :     {
      47             :       // make pair
      48             :       std::pair<dof_id_type, unsigned int> elem_side_pair =
      49        1126 :           std::make_pair(std::get<0>(elem_side_bid[i]), std::get<1>(elem_side_bid[i]));
      50             :       // initialize map elemenet
      51        1126 :       std::vector<Real> var_values(0, 0);
      52             : 
      53             :       // add entry to the value map
      54        1126 :       _map_values[elem_side_pair] = var_values;
      55        1126 :       _map_JxW[elem_side_pair] = var_values;
      56        1126 :     }
      57             :   }
      58         231 : }
      59             : 
      60             : void
      61        3278 : InterfaceQpUserObjectBase::execute()
      62             : {
      63             :   // find the entry on the map
      64        3278 :   auto it = _map_values.find(std::make_pair(_current_elem->id(), _current_side));
      65        3278 :   if (it != _map_values.end())
      66             :   {
      67             :     // insert two vector value for each qp
      68        3278 :     auto & vec = _map_values[std::make_pair(_current_elem->id(), _current_side)];
      69        3278 :     vec.resize(_qrule->n_points());
      70        3278 :     auto & jxw = _map_JxW[std::make_pair(_current_elem->id(), _current_side)];
      71        3278 :     jxw.resize(_qrule->n_points());
      72             : 
      73             :     // loop over qps and do stuff
      74       11024 :     for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
      75             :     {
      76             :       // compute average value at qp
      77        7746 :       vec[qp] = computeRealValue(qp);
      78        7746 :       jxw[qp] = _JxW[qp];
      79             :     }
      80             :   }
      81             :   else
      82           0 :     mooseError("InterfaceQpUserObjectBase:: cannot find the required element and side");
      83        3278 : }
      84             : 
      85             : Real
      86        4176 : InterfaceQpUserObjectBase::getQpValue(const dof_id_type elem,
      87             :                                       const unsigned int side,
      88             :                                       const unsigned int qp) const
      89             : {
      90        4176 :   auto data = _map_values.find(std::make_pair(elem, side));
      91        4176 :   if (data != _map_values.end())
      92        4176 :     return data->second[qp];
      93             :   else
      94           0 :     mooseError("getQpValue: can't find the given qp");
      95             : }
      96             : 
      97             : Real
      98           0 : InterfaceQpUserObjectBase::getSideAverageValue(const dof_id_type elem,
      99             :                                                const unsigned int side) const
     100             : {
     101           0 :   auto data = _map_values.find(std::make_pair(elem, side));
     102           0 :   if (data == _map_values.end())
     103           0 :     mooseError("getSideAverageValue: can't find the given qp");
     104           0 :   auto weights = _map_JxW.find(std::make_pair(elem, side));
     105           0 :   if (weights == _map_JxW.end())
     106           0 :     mooseError("getSideAverageValue: can't find the given qp");
     107             : 
     108           0 :   Real vol = 0;
     109           0 :   Real val = 0;
     110           0 :   for (unsigned int i = 0; i < data->second.size(); i++)
     111             :   {
     112           0 :     val += data->second[i] * weights->second[i];
     113           0 :     vol += weights->second[i];
     114             :   }
     115           0 :   return val / vol;
     116             : }

Generated by: LCOV version 1.14