LCOV - code coverage report
Current view: top level - src/auxkernels - GlobalDisplacementAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 38 41 92.7 %
Date: 2025-07-25 05:00:39 Functions: 3 3 100.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 "GlobalDisplacementAux.h"
      11             : #include "GlobalStrainUserObjectInterface.h"
      12             : 
      13             : // MOOSE includes
      14             : #include "Assembly.h"
      15             : #include "SystemBase.h"
      16             : #include "RankTwoTensor.h"
      17             : 
      18             : registerMooseObject("SolidMechanicsApp", GlobalDisplacementAux);
      19             : 
      20             : InputParameters
      21         300 : GlobalDisplacementAux::validParams()
      22             : {
      23         300 :   InputParameters params = AuxKernel::validParams();
      24         300 :   params.addClassDescription(
      25             :       "AuxKernel to visualize the displacements generated by the global strain tensor");
      26         600 :   params.addCoupledVar("scalar_global_strain",
      27             :                        "Scalar variable providing global strain components");
      28         600 :   params.addCoupledVar("displacements", "The name of the displacement variables");
      29         600 :   params.addRequiredParam<unsigned int>("component",
      30             :                                         "The displacement component to consider for this kernel");
      31         600 :   params.addParam<bool>(
      32         600 :       "output_global_displacement", false, "Option to output global displacement only");
      33         600 :   params.addRequiredParam<UserObjectName>("global_strain_uo",
      34             :                                           "The name of the GlobalStrainUserObject");
      35         300 :   params.addParam<Point>("reference_point",
      36         300 :                          Point(0, 0, 0),
      37             :                          "The coordinate of the center/fixed point of the simulation");
      38             : 
      39             :   // Default this object to get executed before the displaced mesh update.
      40             :   // This way the AuxVars set by this object can be used as mesh displacements.
      41         300 :   params.set<ExecFlagEnum>("execute_on") = EXEC_PRE_DISPLACE;
      42             : 
      43         300 :   return params;
      44           0 : }
      45             : 
      46         150 : GlobalDisplacementAux::GlobalDisplacementAux(const InputParameters & parameters)
      47             :   : AuxKernel(parameters),
      48         150 :     _scalar_global_strain(coupledScalarValue("scalar_global_strain")),
      49         300 :     _component(getParam<unsigned int>("component")),
      50         300 :     _output_global_disp(getParam<bool>("output_global_displacement")),
      51         150 :     _pst(dynamic_cast<const GlobalStrainUserObjectInterface &>(
      52         150 :         getUserObjectBase("global_strain_uo"))),
      53         150 :     _periodic_dir(_pst.getPeriodicDirections()),
      54         150 :     _ref_point(parameters.get<Point>("reference_point")),
      55         150 :     _dim(_mesh.dimension()),
      56         150 :     _ndisp(coupledComponents("displacements")),
      57         450 :     _disp(coupledValues("displacements"))
      58             : {
      59         150 :   if (!isNodal())
      60           0 :     paramError("variable", "GlobalDisplacementAux must be used on a nodal auxiliary variable");
      61             : 
      62         150 :   if (_component >= _dim)
      63           0 :     paramError("component",
      64             :                "The component ",
      65             :                _component,
      66             :                " does not exist for ",
      67             :                _dim,
      68             :                " dimensional problems");
      69         150 : }
      70             : 
      71             : Real
      72       23942 : GlobalDisplacementAux::computeValue()
      73             : {
      74       23942 :   RankTwoTensor strain;
      75       23942 :   strain.fillFromScalarVariable(_scalar_global_strain);
      76             : 
      77       85512 :   for (unsigned int dir = 0; dir < _dim; ++dir)
      78       61570 :     if (!_periodic_dir(dir))
      79       63288 :       for (unsigned int var = 0; var < _ndisp; ++var)
      80       47322 :         strain(dir, var) = 0.0;
      81             : 
      82       23942 :   const RealVectorValue & global_disp = strain * ((*_current_node) - _ref_point);
      83             : 
      84       23942 :   if (_output_global_disp)
      85         648 :     return global_disp(_component);
      86             :   else
      87       23294 :     return global_disp(_component) + (*_disp[_component])[_qp];
      88             : }

Generated by: LCOV version 1.14