https://mooseframework.inl.gov
Loading...
Searching...
No Matches
NodalPatchRecoveryAuxBase.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
14{
16 params.addClassDescription("This Auxkernel solves a least squares problem at each node to fit a "
17 "value from quantities defined on quadrature points.");
18 params.addRequiredParam<UserObjectName>(
19 "nodal_patch_recovery_uo",
20 "The name of the userobject that sets up the least squares problem of the nodal patch.");
21 return params;
22}
23
25 : AuxKernel(parameters)
26{
27 if (!isNodal())
28 mooseError(name(), " only runs on nodal variables.");
29}
30
31Real
33{
34 // get node-to-conneted-elem map
35 const auto & node_to_elem_map = _mesh.nodeToElemMap();
36 auto node_to_elem_pair = node_to_elem_map.find(_current_node->id());
37 mooseAssert(node_to_elem_pair != node_to_elem_map.end(), "Missing entry in node to elem map");
38
39 _elem_ids.clear();
40 blockRestrictElements(_elem_ids, node_to_elem_pair->second);
41
42 // consider the case for corner node
43 if (_elem_ids.size() == 1)
44 {
45 const dof_id_type elem_id = _elem_ids[0];
46 for (auto & n : _mesh.elemPtr(elem_id)->node_ref_range())
47 {
48 node_to_elem_pair = node_to_elem_map.find(n.id());
49 std::vector<dof_id_type> elem_ids_candidate = node_to_elem_pair->second;
50 if (elem_ids_candidate.size() > _elem_ids.size())
51 {
52 std::vector<dof_id_type> elem_ids_candidate_restricted;
53 blockRestrictElements(elem_ids_candidate_restricted, elem_ids_candidate);
54
55 if (elem_ids_candidate_restricted.size() > _elem_ids.size())
56 _elem_ids = elem_ids_candidate_restricted;
57 }
58 }
59 }
60
61 // get the value from a userobject (overridden in derived class)
62 return nodalPatchRecovery();
63}
64
65void
67 std::vector<dof_id_type> & elem_ids,
68 const std::vector<dof_id_type> & node_to_elem_pair_elems) const
69{
70 if (blockRestricted())
71 for (auto elem_id : node_to_elem_pair_elems)
72 {
73 for (const auto block_id : blockIDs())
74 if (block_id == _mesh.elemPtr(elem_id)->subdomain_id())
75 elem_ids.push_back(elem_id);
76 }
77 else
78 elem_ids = node_to_elem_pair_elems;
79}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
MooseMesh & _mesh
Mesh this kernel is active on.
bool isNodal() const
Nodal or elemental kernel?
Definition AuxKernel.h:43
const Node *const & _current_node
Current node (valid only for nodal kernels)
Definition AuxKernel.h:143
static InputParameters validParams()
Definition AuxKernel.C:27
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted,...
virtual bool blockRestricted() const
Returns true if this object has been restricted to a block.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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...
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.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
virtual Elem * elemPtr(const dof_id_type i)
Definition MooseMesh.C:3214
const std::unordered_map< dof_id_type, std::vector< dof_id_type > > & nodeToElemMap()
If not already created, creates a map from every node to all elements to which they are connected.
Definition MooseMesh.C:1236
virtual Real computeValue() override
Compute and return the value of the aux variable.
virtual Real nodalPatchRecovery()=0
Override this to get the fitted value from a Nodal Patch Recovery User Object.
std::vector< dof_id_type > _elem_ids
local patch of elements used for recovery
void blockRestrictElements(std::vector< dof_id_type > &elem_ids, const std::vector< dof_id_type > &node_to_elem_pair_elems) const
Block restrict elements on which to perform the variable/property nodal recovery.
NodalPatchRecoveryAuxBase(const InputParameters &parameters)
static InputParameters validParams()