https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MeshAlignmentVariableTransferMaterial.C
Go to the documentation of this file.
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
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
22
25{
27
28 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 params.addRequiredParam<std::string>("paired_variable", "The variable to get the value of.");
33 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 params.addRequiredParam<MeshAlignment *>("_mesh_alignment", "Mesh alignment object");
38 return params;
39}
40
42 const InputParameters & parameters)
43 : Material(parameters),
44 _nl_sys(_subproblem.systemBaseNonlinear(/*nl_sys_num=*/0)),
45 _serialized_solution(_nl_sys.currentSolution()),
46 _paired_variable(
47 _subproblem.getVariable(_tid, getParam<std::string>("paired_variable"), Moose::VAR_SOLVER)
48 .number()),
49 _mesh_alignment(*getParam<MeshAlignment *>("_mesh_alignment")),
50 _prop(declareADProperty<Real>(getParam<MaterialPropertyName>("property_name"))),
51 _phi(_assembly.fePhi<Real>(FEType(FIRST, LAGRANGE)))
52{
53}
54
55void
57{
58 std::vector<ADReal> nodal_values;
59 for (const auto i : _current_elem->node_index_range())
60 {
61 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 const auto coupled_node_id = _mesh_alignment.getCoupledNodeID(node.id());
65 const Node * const coupled_node = _mesh.nodePtr(coupled_node_id);
66 const auto dof_number = coupled_node->dof_number(_nl_sys.number(), _paired_variable, 0);
67 nodal_values.push_back((*_serialized_solution)(dof_number));
68 Moose::derivInsert(nodal_values.back().derivatives(), dof_number, 1.0);
69 }
70
71 for (const auto qp : make_range(_qrule->n_points()))
72 {
73 _prop[qp] = 0;
74 for (const auto i : _current_elem->node_index_range())
75 _prop[qp] += nodal_values[i] * _phi[i][qp];
76 }
77}
registerMooseObject("ThermalHydraulicsApp", MeshAlignmentVariableTransferMaterial)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
MooseMesh & _mesh
static InputParameters validParams()
const Elem *const & _current_elem
const QBase *const & _qrule
Creates an AD material property for a variable transferred from the boundary of a 2D mesh onto a 1D m...
MeshAlignmentVariableTransferMaterial(const InputParameters &parameters)
const VariablePhiValue & _phi
Basis function for transferred variable.
ADMaterialProperty< Real > & _prop
Material property for the transferred variable.
unsigned int _paired_variable
Variable number of the variable to transfer.
const NumericVector< Number > *const & _serialized_solution
Solution vector.
const MeshAlignment & _mesh_alignment
Mesh alignment object.
Builds mapping between two aligned subdomains/boundaries.
const dof_id_type & getCoupledNodeID(const dof_id_type &node_id) const
Gets the coupled node ID for a given node ID.
virtual const Node * nodePtr(const dof_id_type i) const
unsigned int number() const
void derivInsert(SemiDynamicSparseNumberArray< Real, libMesh::dof_id_type, NWrapper< N > > &derivs, libMesh::dof_id_type index, Real value)