LCOV - code coverage report
Current view: top level - src/postprocessors - NormalBoundaryDisplacement.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 56 73 76.7 %
Date: 2025-07-25 05:00:39 Functions: 6 7 85.7 %
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 "NormalBoundaryDisplacement.h"
      11             : 
      12             : #include "libmesh/quadrature.h"
      13             : 
      14             : registerMooseObject("SolidMechanicsApp", NormalBoundaryDisplacement);
      15             : 
      16             : InputParameters
      17          48 : NormalBoundaryDisplacement::validParams()
      18             : {
      19          48 :   InputParameters params = SidePostprocessor::validParams();
      20          96 :   params.addRequiredCoupledVar("displacements", "The names of the displacement variables");
      21          96 :   MooseEnum type_options("average=0 absolute_average=1 max=2 absolute_max=3");
      22          96 :   params.addRequiredParam<MooseEnum>(
      23             :       "value_type", type_options, "Type of extreme value to return.");
      24          48 :   params.addClassDescription(
      25             :       "This postprocessor computes the normal displacement on a given set of boundaries.");
      26          48 :   return params;
      27          48 : }
      28             : 
      29          24 : NormalBoundaryDisplacement::NormalBoundaryDisplacement(const InputParameters & parameters)
      30             :   : SidePostprocessor(parameters),
      31          24 :     _value_type(getParam<MooseEnum>("value_type").getEnum<NormalValType>()),
      32          48 :     _ncomp(coupledComponents("displacements"))
      33             : {
      34          24 :   if (_ncomp != _mesh.dimension())
      35           0 :     paramError("displacements", "Number of entries must match the mesh dimension.");
      36             : 
      37          24 :   _disp.resize(_ncomp);
      38          72 :   for (unsigned int j = 0; j < _ncomp; ++j)
      39          48 :     _disp[j] = &coupledValue("displacements", j);
      40          24 : }
      41             : 
      42             : void
      43          24 : NormalBoundaryDisplacement::initialize()
      44             : {
      45          24 :   _boundary_displacement = 0;
      46          24 :   _area = 0;
      47          24 : }
      48             : 
      49             : void
      50          48 : NormalBoundaryDisplacement::execute()
      51             : {
      52          96 :   for (unsigned int qp = 0; qp < _qrule->n_points(); qp++)
      53             :   {
      54             :     Real ddn = 0;
      55         144 :     for (unsigned int j = 0; j < _ncomp; ++j)
      56          96 :       ddn += _normals[qp](j) * (*_disp[j])[qp];
      57             : 
      58          48 :     _area += _JxW[qp] * _coord[qp];
      59          48 :     switch (_value_type)
      60             :     {
      61          12 :       case NormalValType::AVERAGE:
      62          12 :         _boundary_displacement += _JxW[qp] * _coord[qp] * ddn;
      63          12 :         break;
      64          12 :       case NormalValType::ABSOLUTE_AVERAGE:
      65          12 :         _boundary_displacement += _JxW[qp] * _coord[qp] * std::abs(ddn);
      66          12 :         break;
      67          12 :       case NormalValType::MAX:
      68          12 :         if (ddn > _boundary_displacement)
      69           4 :           _boundary_displacement = ddn;
      70             :         break;
      71             :       case NormalValType::ABSOLUTE_MAX:
      72             :         ddn = std::abs(ddn);
      73          12 :         if (ddn > _boundary_displacement)
      74           4 :           _boundary_displacement = ddn;
      75             :         break;
      76             :     }
      77             :   }
      78          48 : }
      79             : 
      80             : Real
      81          24 : NormalBoundaryDisplacement::getValue() const
      82             : {
      83          24 :   return _boundary_displacement;
      84             : }
      85             : 
      86             : void
      87           0 : NormalBoundaryDisplacement::threadJoin(const UserObject & y)
      88             : {
      89             :   const auto & pps = static_cast<const NormalBoundaryDisplacement &>(y);
      90             : 
      91           0 :   switch (_value_type)
      92             :   {
      93           0 :     case NormalValType::AVERAGE:
      94           0 :       _boundary_displacement += pps._boundary_displacement;
      95           0 :       break;
      96           0 :     case NormalValType::ABSOLUTE_AVERAGE:
      97           0 :       _boundary_displacement += pps._boundary_displacement;
      98           0 :       break;
      99           0 :     case NormalValType::MAX:
     100           0 :       if (pps._boundary_displacement > _boundary_displacement)
     101           0 :         _boundary_displacement = pps._boundary_displacement;
     102             :       break;
     103           0 :     case NormalValType::ABSOLUTE_MAX:
     104           0 :       if (pps._boundary_displacement > _boundary_displacement)
     105           0 :         _boundary_displacement = pps._boundary_displacement;
     106             :       break;
     107             :   }
     108             : 
     109           0 :   _area += pps._area;
     110           0 : }
     111             : 
     112             : void
     113          24 : NormalBoundaryDisplacement::finalize()
     114             : {
     115          24 :   gatherSum(_area);
     116          24 :   switch (_value_type)
     117             :   {
     118           6 :     case NormalValType::AVERAGE:
     119           6 :       gatherSum(_boundary_displacement);
     120           6 :       _boundary_displacement /= _area;
     121           6 :       break;
     122           6 :     case NormalValType::ABSOLUTE_AVERAGE:
     123           6 :       gatherSum(_boundary_displacement);
     124           6 :       _boundary_displacement /= _area;
     125           6 :       break;
     126           6 :     case NormalValType::MAX:
     127           6 :       gatherMax(_boundary_displacement);
     128             :       break;
     129           6 :     case NormalValType::ABSOLUTE_MAX:
     130           6 :       gatherMax(_boundary_displacement);
     131             :       break;
     132             :   }
     133          24 : }

Generated by: LCOV version 1.14