https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ProjectionAux.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
10#include "ProjectionAux.h"
11#include "SystemBase.h"
12#include "libmesh/system.h"
13
14registerMooseObjectRenamed("MooseApp", SelfAux, "01/30/2024 24:00", ProjectionAux);
16
19{
22 "Returns the specified variable as an auxiliary variable with a projection of the source "
23 "variable. If they are the same type, this amounts to a simple copy.");
24 params.addRequiredCoupledVar("v", "Variable to take the value of.");
25
26 params.addParam<bool>("use_block_restriction_for_source",
27 false,
28 "Whether to use the auxkernel block restriction to also restrict the "
29 "locations selected for source variable values");
30
31 // Technically possible to project from nodal to elemental and back
32 params.set<bool>("_allow_nodal_to_elemental_coupling") = true;
33
34 MooseEnum elem_to_node_projection_weighting("volume identity", "volume");
35 params.addParam<MooseEnum>("elem_to_node_projection_weighting",
36 elem_to_node_projection_weighting,
37 "How to weight individual element contributions when projecting to a "
38 "nodal degree of freedom");
39
40 // We need some ghosting for all elemental to nodal projections
42 "GhostAllPointNeighbors",
44 [](const InputParameters & obj_params, InputParameters & rm_params)
45 { rm_params.set<bool>("use_displaced_mesh") = obj_params.get<bool>("use_displaced_mesh"); });
46 return params;
47}
48
50 : AuxKernel(parameters),
51 _v(coupledValue("v")),
52 _source_variable(*getFieldVar("v", 0)),
53 _source_sys(_c_fe_problem.getSystem(coupledName("v"))),
54 _use_block_restriction_for_source(getParam<bool>("use_block_restriction_for_source")),
55 _elem_to_node_projection_weighting(getParam<MooseEnum>("elem_to_node_projection_weighting")
57{
58 // Output some messages to user
60 mooseInfo("Projection lowers order, please expect a loss of accuracy");
61}
62
63Real
65{
67 return _v[_qp];
68 // projecting continuous variable onto a nodal one
69 // AND projecting from low order -> nodal higher order
70 else if (isNodal() && _source_variable.getContinuity() != DISCONTINUOUS &&
71 _source_variable.getContinuity() != SIDE_DISCONTINUOUS)
74 // Handle discontinuous elemental variable projection into a nodal variable
75 else
76 {
77 // Custom projection rule : use nodal values, if discontinuous the one coming from each element,
78 // weighted by element volumes
79 // First, find all the elements that this node is part of
80 const auto & elem_ids = libmesh_map_find(_mesh.nodeToElemMap(), _current_node->id());
81
82 // Get the neighbor element centroid values & element volumes
83 Real sum_weighted_values = 0;
84 Real sum_weights = 0;
85 _elem_dims.clear();
86 for (const auto id : elem_ids)
87 {
88 const auto * const elem = _mesh.elemPtr(id);
89 const auto block_id = elem->subdomain_id();
90 if (_source_variable.hasBlocks(block_id) &&
92 {
94 _elem_dims.insert(elem->dim());
95 const auto elem_weight =
97 sum_weighted_values +=
99 sum_weights += elem_weight;
100 }
101 }
102 if (sum_weights == 0)
103 mooseError("Did not find a valid source variable value for node: ", *_current_node);
105 mooseError("We should not use multiple element dimensions when computing the volume weighted "
106 "projection as the units do not make sense");
107 return sum_weighted_values / sum_weights;
108 }
109}
110
111const Elem *
113{
114 for (const auto & elem_id : _mesh.nodeToElemMap().find(_current_node->id())->second)
115 {
116 const auto & elem = _mesh.elemPtr(elem_id);
117 const auto block_id = elem->subdomain_id();
118 if (_source_variable.hasBlocks(block_id) &&
120 return elem;
121 }
122 mooseError("Source variable is not defined everywhere the target variable is");
123}
void mooseInfo(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
Definition MooseError.h:401
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
registerMooseObjectRenamed("MooseApp", SelfAux, "01/30/2024 24:00", ProjectionAux)
registerMooseObject("MooseApp", ProjectionAux)
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
unsigned int _qp
Quadrature point index.
Definition AuxKernel.h:155
MooseVariableField< Real > & _var
This is a regular kernel so we cast to a regular MooseVariable, hides base _var.
Definition AuxKernel.h:113
static InputParameters validParams()
Definition AuxKernel.C:27
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
void addRelationshipManager(const std::string &name, Moose::RelationshipManagerType rm_type, Moose::RelationshipManagerInputParameterCallback input_parameter_callback=nullptr)
Tells MOOSE about a RelationshipManager that this object needs.
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
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 bool isNodal() const
Is this variable nodal.
virtual libMesh::FEContinuity getContinuity() const
Return the continuity of this variable.
libMesh::Order order() const
Get the order of this variable Note: Order enum can be implicitly converted to unsigned int.
unsigned int number() const
Get variable number coming from libMesh.
Projects from one variable to another.
const VariableValue & _v
The variable to project from.
bool _use_block_restriction_for_source
Whether to use the auxkernel block restriction to limit the values for the source variables.
static InputParameters validParams()
virtual Real computeValue() override
Compute and return the value of the aux variable.
ProjectionAux(const InputParameters &parameters)
const MooseVariableFieldBase & _source_variable
A reference to the variable to project from We must use a field variable to support finite volume var...
std::unordered_set< unsigned short > _elem_dims
Set for holding element dimensions when mapping from multiple element values to a node.
const libMesh::System & _source_sys
The system owning the source variable.
const Elem * elemOnNodeVariableIsDefinedOn() const
For a node, finds an element we can use to evaluate the (continuous) source variable.
const ElemToNodeProjectionWeighting _elem_to_node_projection_weighting
How to weight element to node projections.
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const