www.mooseframework.org
NearestNodeValueAux.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "NearestNodeValueAux.h"
11 
12 #include "SystemBase.h"
13 #include "NearestNodeLocator.h"
14 
16 
17 template <>
20 {
22  params.addClassDescription("Retrieves a field value from the closest node on the paired boundary "
23  "and stores it on this boundary or block.");
24  params.set<bool>("_dual_restrictable") = true;
25  params.addRequiredParam<BoundaryName>("paired_boundary", "The boundary to get the value from.");
26  params.addRequiredCoupledVar("paired_variable", "The variable to get the value of.");
27  params.set<bool>("use_displaced_mesh") = true;
28  return params;
29 }
30 
32  : AuxKernel(parameters),
33  _nearest_node(
34  getNearestNodeLocator(parameters.get<BoundaryName>("paired_boundary"), boundaryNames()[0])),
35  _serialized_solution(_nl_sys.currentSolution()),
36  _paired_variable(coupled("paired_variable"))
37 {
38  if (boundaryNames().size() > 1)
39  mooseError("NearestNodeValueAux can only be used with one boundary at a time!");
40 }
41 
42 Real
44 {
45  // Assumes the variable you are coupling to is from the nonlinear system for now.
46  const Node * nearest = _nearest_node.nearestNode(_current_node->id());
47  mooseAssert(nearest != NULL, "I do not have the nearest node for you");
48  dof_id_type dof_number = nearest->dof_number(_nl_sys.number(), _paired_variable, 0);
49 
50  return (*_serialized_solution)(dof_number);
51 }
const NumericVector< Number > *const & _serialized_solution
registerMooseObject("MooseApp", NearestNodeValueAux)
const Node *const & _current_node
Current node (valid only for nodal kernels)
Definition: AuxKernel.h:213
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
SystemBase & _nl_sys
Definition: AuxKernel.h:160
InputParameters validParams< AuxKernel >()
Definition: AuxKernel.C:25
NearestNodeLocator & _nearest_node
virtual unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:926
virtual Real computeValue() override
Compute and return the value of the aux variable.
Finds the closest node on a paired boundary to the current node or element and stores a corresponding...
NearestNodeValueAux(const InputParameters &parameters)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
const Node * nearestNode(dof_id_type node_id)
Valid to call this after findNodes() has been called to get a pointer to the nearest node...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition: AuxKernel.h:33
unsigned int _paired_variable
const std::vector< BoundaryName > & boundaryNames() const
Return the boundary names for this object.
InputParameters validParams< NearestNodeValueAux >()