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 666 : MeshAlignmentVariableTransferMaterial::validParams() 25 : { 26 666 : InputParameters params = Material::validParams(); 27 : 28 666 : 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 1332 : params.addRequiredParam<std::string>("paired_variable", "The variable to get the value of."); 33 1332 : 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 1332 : params.addRequiredParam<MeshAlignment *>("_mesh_alignment", "Mesh alignment object"); 38 666 : return params; 39 0 : } 40 : 41 519 : MeshAlignmentVariableTransferMaterial::MeshAlignmentVariableTransferMaterial( 42 519 : const InputParameters & parameters) 43 : : Material(parameters), 44 1038 : _nl_sys(_subproblem.systemBaseNonlinear(/*nl_sys_num=*/0)), 45 519 : _serialized_solution(_nl_sys.currentSolution()), 46 519 : _paired_variable( 47 1038 : _subproblem.getVariable(_tid, getParam<std::string>("paired_variable"), Moose::VAR_SOLVER) 48 : .number()), 49 1038 : _mesh_alignment(*getParam<MeshAlignment *>("_mesh_alignment")), 50 1038 : _prop(declareADProperty<Real>(getParam<MaterialPropertyName>("property_name"))), 51 1038 : _phi(_assembly.fePhi<Real>(FEType(FIRST, LAGRANGE))) 52 : { 53 519 : } 54 : 55 : void 56 314345 : MeshAlignmentVariableTransferMaterial::computeProperties() 57 : { 58 : std::vector<ADReal> nodal_values; 59 943035 : for (const auto i : _current_elem->node_index_range()) 60 : { 61 628690 : 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 628690 : const auto coupled_node_id = _mesh_alignment.getCoupledNodeID(node.id()); 65 628690 : const Node * const coupled_node = _mesh.nodePtr(coupled_node_id); 66 628690 : const auto dof_number = coupled_node->dof_number(_nl_sys.number(), _paired_variable, 0); 67 1257380 : nodal_values.push_back((*_serialized_solution)(dof_number)); 68 : Moose::derivInsert(nodal_values.back().derivatives(), dof_number, 1.0); 69 : } 70 : 71 832465 : for (const auto qp : make_range(_qrule->n_points())) 72 : { 73 518120 : _prop[qp] = 0; 74 1554360 : for (const auto i : _current_elem->node_index_range()) 75 2072480 : _prop[qp] += nodal_values[i] * _phi[i][qp]; 76 : } 77 314345 : }