LCOV - code coverage report
Current view: top level - src/materials - MeshAlignmentVariableTransferMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #30301 (3b550b) with base 2ad78d Lines: 29 30 96.7 %
Date: 2025-07-30 13:02:48 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 "MeshAlignmentVariableTransferMaterial.h"
      11             : #include "SubProblem.h"
      12             : #include "SystemBase.h"
      13             : #include "Assembly.h"
      14             : #include "ADUtils.h"
      15             : #include "MooseVariableBase.h"
      16             : #include "MeshAlignment.h"
      17             : 
      18             : #include "libmesh/node.h"
      19             : #include "libmesh/elem.h"
      20             : 
      21             : registerMooseObject("ThermalHydraulicsApp", MeshAlignmentVariableTransferMaterial);
      22             : 
      23             : InputParameters
      24        1410 : MeshAlignmentVariableTransferMaterial::validParams()
      25             : {
      26        1410 :   InputParameters params = Material::validParams();
      27             : 
      28        1410 :   params.addClassDescription("Creates an AD material property for a variable transferred from the "
      29             :                              "boundary of a 2D mesh onto a 1D mesh.");
      30             : 
      31             :   // Have to use std::string to circumvent block restrictable testing
      32        2820 :   params.addRequiredParam<std::string>("paired_variable", "The variable to get the value of.");
      33        2820 :   params.addRequiredParam<MaterialPropertyName>(
      34             :       "property_name",
      35             :       "The name of the material property that will be "
      36             :       "declared that will represent the transferred variable.");
      37        2820 :   params.addRequiredParam<MeshAlignment *>("_mesh_alignment", "Mesh alignment object");
      38        1410 :   return params;
      39           0 : }
      40             : 
      41        1122 : MeshAlignmentVariableTransferMaterial::MeshAlignmentVariableTransferMaterial(
      42        1122 :     const InputParameters & parameters)
      43             :   : Material(parameters),
      44        2244 :     _nl_sys(_subproblem.systemBaseNonlinear(/*nl_sys_num=*/0)),
      45        1122 :     _serialized_solution(_nl_sys.currentSolution()),
      46        1122 :     _paired_variable(
      47        2244 :         _subproblem.getVariable(_tid, getParam<std::string>("paired_variable"), Moose::VAR_SOLVER)
      48             :             .number()),
      49        2244 :     _mesh_alignment(*getParam<MeshAlignment *>("_mesh_alignment")),
      50        2244 :     _prop(declareADProperty<Real>(getParam<MaterialPropertyName>("property_name"))),
      51        2244 :     _phi(_assembly.fePhi<Real>(FEType(FIRST, LAGRANGE)))
      52             : {
      53        1122 : }
      54             : 
      55             : void
      56      810658 : MeshAlignmentVariableTransferMaterial::computeProperties()
      57             : {
      58             :   std::vector<ADReal> nodal_values;
      59     2431974 :   for (const auto i : _current_elem->node_index_range())
      60             :   {
      61     1621316 :     const Node & node = _current_elem->node_ref(i);
      62             : 
      63             :     // Assumes the variable you are coupling to is from the nonlinear system for now.
      64     1621316 :     const auto coupled_node_id = _mesh_alignment.getCoupledNodeID(node.id());
      65     1621316 :     const Node * const coupled_node = _mesh.nodePtr(coupled_node_id);
      66     1621316 :     const auto dof_number = coupled_node->dof_number(_nl_sys.number(), _paired_variable, 0);
      67     3242632 :     nodal_values.push_back((*_serialized_solution)(dof_number));
      68             :     Moose::derivInsert(nodal_values.back().derivatives(), dof_number, 1.0);
      69             :   }
      70             : 
      71     2107911 :   for (const auto qp : make_range(_qrule->n_points()))
      72             :   {
      73     1297253 :     _prop[qp] = 0;
      74     3891759 :     for (const auto i : _current_elem->node_index_range())
      75     5189012 :       _prop[qp] += nodal_values[i] * _phi[i][qp];
      76             :   }
      77      810658 : }

Generated by: LCOV version 1.14