LCOV - code coverage report
Current view: top level - src/postprocessor - AverageExtensionRatio.C (source / functions) Hit Total Coverage
Test: idaholab/blackbear: b15b36 Lines: 33 34 97.1 %
Date: 2025-07-18 16:15:14 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "AverageExtensionRatio.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "Function.h"
      14             : #include "MooseMesh.h"
      15             : #include "MooseVariable.h"
      16             : #include "SubProblem.h"
      17             : 
      18             : #include "libmesh/system.h"
      19             : 
      20             : #include "ComputeIncrementalBeamStrain.h"
      21             : #include "Assembly.h"
      22             : #include "NonlinearSystem.h"
      23             : 
      24             : #include "libmesh/quadrature.h"
      25             : #include "libmesh/utility.h"
      26             : 
      27             : registerMooseObject("BlackBearApp", AverageExtensionRatio);
      28             : 
      29             : InputParameters
      30          32 : AverageExtensionRatio::validParams()
      31             : {
      32          32 :   InputParameters params = GeneralPostprocessor::validParams();
      33          64 :   params.addRequiredParam<std::vector<VariableName>>(
      34             :       "displacements",
      35             :       "The displacements appropriate for the simulation geometry and coordinate system");
      36          64 :   params.addRequiredParam<std::vector<Point>>("first_point",
      37             :                                               "A list of first points in the numerical domain");
      38          64 :   params.addRequiredParam<std::vector<Point>>("last_point",
      39             :                                               "A list of last points in the numerical domain");
      40          32 :   params.addClassDescription(
      41             :       "Computes the average extension ratio on deformed mesh between two sets of points");
      42          32 :   return params;
      43           0 : }
      44             : 
      45          19 : AverageExtensionRatio::AverageExtensionRatio(const InputParameters & parameters)
      46             :   : GeneralPostprocessor(parameters),
      47          19 :     _displacements(getParam<std::vector<VariableName>>("displacements")),
      48             : 
      49          19 :     _system(_subproblem.getSystem(_displacements[0])),
      50          38 :     _first_point(getParam<std::vector<Point>>("first_point")),
      51          38 :     _last_point(getParam<std::vector<Point>>("last_point")),
      52          57 :     _value(0)
      53             : {
      54          19 :   _disp_num = std::vector<int>(_displacements.size());
      55          76 :   for (unsigned int i = 0; i < _displacements.size(); ++i)
      56          57 :     _disp_num[i] = _subproblem
      57          57 :                        .getVariable(_tid,
      58             :                                     _displacements[i],
      59             :                                     Moose::VarKindType::VAR_ANY,
      60             :                                     Moose::VarFieldType::VAR_FIELD_STANDARD)
      61          57 :                        .number();
      62             : 
      63          19 :   if (_first_point.size() != _last_point.size() || _first_point.size() == 0)
      64           6 :     mooseError("Sizes of 'first_point' and 'last_point' arrays must match and be postive.");
      65          13 : }
      66             : 
      67             : void
      68          10 : AverageExtensionRatio::execute()
      69             : {
      70          10 :   _value = 0.;
      71             :   Real sq_extension, sq_distance;
      72          30 :   for (unsigned int i = 0; i < _first_point.size(); ++i)
      73             :   {
      74             :     sq_extension = 0;
      75             :     sq_distance = 0;
      76          80 :     for (unsigned int j = 0; j < _displacements.size(); ++j)
      77             :     {
      78         120 :       sq_extension += Utility::pow<2>(_system.point_value(_disp_num[j], _first_point[i], false) -
      79          60 :                                       _system.point_value(_disp_num[j], _last_point[i], false));
      80          60 :       sq_distance += Utility::pow<2>(_first_point[i](j) - _last_point[i](j));
      81             :     }
      82          20 :     _value += std::sqrt(sq_extension) / std::sqrt(sq_distance);
      83             :   }
      84          10 :   _value = _value / _first_point.size();
      85          10 : }
      86             : 
      87             : Real
      88          10 : AverageExtensionRatio::getValue() const
      89             : {
      90          10 :   return _value;
      91             : }

Generated by: LCOV version 1.14