LCOV - code coverage report
Current view: top level - src/materials - TrussMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: #32971 (54bef8) with base c6cf66 Lines: 42 43 97.7 %
Date: 2026-05-29 20:40:07 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://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 "TrussMaterial.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "Material.h"
      14             : #include "MooseMesh.h"
      15             : #include "MooseVariable.h"
      16             : #include "NonlinearSystem.h"
      17             : 
      18             : #include "libmesh/quadrature.h"
      19             : 
      20             : InputParameters
      21         178 : TrussMaterial::validParams()
      22             : {
      23         178 :   InputParameters params = Material::validParams();
      24         356 :   params.addParam<std::string>("base_name",
      25             :                                "Optional parameter that allows the user to define "
      26             :                                "multiple mechanics material systems on the same "
      27             :                                "block, i.e. for multiple phases");
      28         356 :   params.addRequiredParam<std::vector<VariableName>>(
      29             :       "displacements",
      30             :       "The displacements appropriate for the simulation geometry and coordinate system");
      31         356 :   params.addCoupledVar("youngs_modulus", "Variable containing Young's modulus");
      32         178 :   return params;
      33           0 : }
      34             : 
      35         134 : TrussMaterial::TrussMaterial(const InputParameters & parameters)
      36             :   : Material(parameters),
      37         268 :     _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
      38         134 :     _youngs_modulus(coupledValue("youngs_modulus")),
      39         134 :     _total_stretch(declareProperty<Real>(_base_name + "total_stretch")),
      40         134 :     _elastic_stretch(declareProperty<Real>(_base_name + "elastic_stretch")),
      41         134 :     _axial_stress(declareProperty<Real>(_base_name + "axial_stress")),
      42         268 :     _e_over_l(declareProperty<Real>(_base_name + "e_over_l"))
      43             : {
      44         268 :   const std::vector<VariableName> & nl_vnames(getParam<std::vector<VariableName>>("displacements"));
      45         134 :   _ndisp = nl_vnames.size();
      46             : 
      47             :   // fetch nonlinear variables
      48         376 :   for (unsigned int i = 0; i < _ndisp; ++i)
      49         242 :     _disp_var.push_back(&_fe_problem.getStandardVariable(_tid, nl_vnames[i]));
      50         134 : }
      51             : 
      52             : void
      53          72 : TrussMaterial::initQpStatefulProperties()
      54             : {
      55          72 :   _axial_stress[_qp] = 0.0;
      56          72 :   _total_stretch[_qp] = 0.0;
      57          72 :   _elastic_stretch[_qp] = 0.0;
      58          72 : }
      59             : 
      60             : void
      61        6444 : TrussMaterial::computeProperties()
      62             : {
      63             :   // check for consistency of the number of element nodes
      64             :   mooseAssert(_current_elem->n_nodes() == 2, "Truss element needs to have exactly two nodes.");
      65             : 
      66             :   // fetch the two end nodes for _current_elem
      67             :   std::vector<const Node *> node;
      68       19332 :   for (unsigned int i = 0; i < 2; ++i)
      69       12888 :     node.push_back(_current_elem->node_ptr(i));
      70             : 
      71             :   // calculate original length of a truss element
      72             :   RealGradient dxyz;
      73       20490 :   for (unsigned int i = 0; i < _ndisp; ++i)
      74       14046 :     dxyz(i) = (*node[1])(i) - (*node[0])(i);
      75        6444 :   _origin_length = dxyz.norm();
      76             : 
      77             :   // fetch the solution for the two end nodes
      78        6444 :   NonlinearSystemBase & nonlinear_sys = _fe_problem.getNonlinearSystemBase(/*nl_sys_num=*/0);
      79        6444 :   const NumericVector<Number> & sol = *nonlinear_sys.currentSolution();
      80             : 
      81             :   std::vector<Real> disp0, disp1;
      82       20490 :   for (unsigned int i = 0; i < _ndisp; ++i)
      83             :   {
      84       14046 :     disp0.push_back(sol(node[0]->dof_number(nonlinear_sys.number(), _disp_var[i]->number(), 0)));
      85       14046 :     disp1.push_back(sol(node[1]->dof_number(nonlinear_sys.number(), _disp_var[i]->number(), 0)));
      86             :   }
      87             : 
      88             :   // calculate current length of a truss element
      89       20490 :   for (unsigned int i = 0; i < _ndisp; ++i)
      90       14046 :     dxyz(i) += disp1[i] - disp0[i];
      91        6444 :   _current_length = dxyz.norm();
      92             : 
      93       19332 :   for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
      94             :   {
      95       12888 :     _e_over_l[_qp] = _youngs_modulus[_qp] / _origin_length;
      96             : 
      97       12888 :     computeQpStrain();
      98       12888 :     computeQpStress();
      99             :   }
     100        6444 : }

Generated by: LCOV version 1.14