LCOV - code coverage report
Current view: top level - src/userobjects - GrainForceAndTorqueSum.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 39 44 88.6 %
Date: 2025-09-04 07:55:36 Functions: 5 7 71.4 %
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 "GrainForceAndTorqueSum.h"
      11             : 
      12             : registerMooseObject("PhaseFieldApp", GrainForceAndTorqueSum);
      13             : 
      14             : InputParameters
      15          22 : GrainForceAndTorqueSum::validParams()
      16             : {
      17          22 :   InputParameters params = GeneralUserObject::validParams();
      18          22 :   params.addClassDescription("Userobject for summing forces and torques acting on a grain");
      19          44 :   params.addParam<std::vector<UserObjectName>>(
      20             :       "grain_forces",
      21             :       "List of names of user objects that provides forces and torques applied to grains");
      22          44 :   params.addParam<unsigned int>("grain_num", "Number of grains");
      23          22 :   return params;
      24           0 : }
      25             : 
      26          11 : GrainForceAndTorqueSum::GrainForceAndTorqueSum(const InputParameters & parameters)
      27             :   : GrainForceAndTorqueInterface(),
      28             :     GeneralUserObject(parameters),
      29          22 :     _sum_objects(getParam<std::vector<UserObjectName>>("grain_forces")),
      30          11 :     _num_forces(_sum_objects.size()),
      31          22 :     _grain_num(getParam<unsigned int>("grain_num")),
      32          11 :     _sum_forces(_num_forces),
      33          11 :     _force_values(_grain_num),
      34          22 :     _torque_values(_grain_num)
      35             : {
      36          33 :   for (unsigned int i = 0; i < _num_forces; ++i)
      37          22 :     _sum_forces[i] = &getUserObjectByName<GrainForceAndTorqueInterface>(_sum_objects[i]);
      38          11 : }
      39             : 
      40             : void
      41         119 : GrainForceAndTorqueSum::initialize()
      42             : {
      43         357 :   for (unsigned int i = 0; i < _grain_num; ++i)
      44             :   {
      45         238 :     _force_values[i] = 0.0;
      46             :     _torque_values[i] = 0.0;
      47         714 :     for (unsigned int j = 0; j < _num_forces; ++j)
      48             :     {
      49         476 :       _force_values[i] += (_sum_forces[j]->getForceValues())[i];
      50         476 :       _torque_values[i] += (_sum_forces[j]->getTorqueValues())[i];
      51             :     }
      52             :   }
      53             : 
      54         119 :   if (_fe_problem.currentlyComputingJacobian())
      55             :   {
      56          51 :     unsigned int total_dofs = _subproblem.es().n_dofs();
      57          51 :     _c_jacobians.resize(6 * _grain_num * total_dofs, 0.0);
      58          51 :     _eta_jacobians.resize(_grain_num);
      59             : 
      60      110211 :     for (unsigned int i = 0; i < _c_jacobians.size(); ++i)
      61      330480 :       for (unsigned int j = 0; j < _num_forces; ++j)
      62      220320 :         _c_jacobians[i] += (_sum_forces[j]->getForceCJacobians())[i];
      63             : 
      64         153 :     for (unsigned int i = 0; i < _grain_num; ++i)
      65             :     {
      66         102 :       _eta_jacobians[i].resize(6 * _grain_num * total_dofs, 0.0);
      67      220422 :       for (unsigned int j = 0; j < _eta_jacobians[i].size(); ++j)
      68      660960 :         for (unsigned int k = 0; k < _num_forces; ++k)
      69      440640 :           _eta_jacobians[i][j] += (_sum_forces[k]->getForceEtaJacobians())[i][j];
      70             :     }
      71             :   }
      72         119 : }
      73             : 
      74             : const std::vector<RealGradient> &
      75          11 : GrainForceAndTorqueSum::getForceValues() const
      76             : {
      77          11 :   return _force_values;
      78             : }
      79             : 
      80             : const std::vector<RealGradient> &
      81          11 : GrainForceAndTorqueSum::getTorqueValues() const
      82             : {
      83          11 :   return _torque_values;
      84             : }
      85             : 
      86             : const std::vector<Real> &
      87           0 : GrainForceAndTorqueSum::getForceCJacobians() const
      88             : {
      89           0 :   return _c_jacobians;
      90             : }
      91             : 
      92             : const std::vector<std::vector<Real>> &
      93           0 : GrainForceAndTorqueSum::getForceEtaJacobians() const
      94             : {
      95           0 :   return _eta_jacobians;
      96             : }

Generated by: LCOV version 1.14