https://mooseframework.inl.gov
Loading...
Searching...
No Matches
VariableValueElementSubdomainModifier.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
13
16{
18
20 "coupled_var", "Coupled variable whose value is used to calculate the desired subdomain ID.");
22 "Modify the element subdomain ID based on the provided variable value.");
23 return params;
24}
25
27 const InputParameters & parameters)
28 : ElementSubdomainModifier(parameters), _v(coupledValue("coupled_var"))
29{
30}
31
34{
35 // Calculate the desired subdomain ID for the current element.
36 Real val = 0.0;
37 for (const auto qp : make_range(_qrule->n_points()))
38 val += _v[qp] * _JxW[qp] * _coord[qp];
40
41 SubdomainID sid = (unsigned int)(round(val));
42
43 // Verify whether the specified target subdomain ID is present within the mesh. If it is not
44 // found, locate the smallest subdomain ID in the mesh that matches or exceeds the target
45 // subdomain ID. Or select the largest subdomain ID present in the mesh if all subdomain IDs are
46 // smaller than the target.
47 if (_mesh.meshSubdomains().find(sid) == _mesh.meshSubdomains().end())
48 {
49 auto it = _mesh.meshSubdomains().lower_bound(sid);
50 SubdomainID lower_bound_id =
51 it == _mesh.meshSubdomains().end() ? *_mesh.meshSubdomains().rbegin() : *it;
52
53 // Store the target subdomain ID if it hasn't been previously requested.
54 // Lock the _void_sids for thread-safe operations.
55 std::lock_guard<std::mutex> lock(_void_sids_mutex);
56 if (_void_sids.find(sid) == _void_sids.end())
57 {
58 mooseWarning("Requested subdomain ",
59 sid,
60 " does not exist. Subdomain ID ",
61 lower_bound_id,
62 " is assigned. Please ensure the passed variable falls within the range of the "
63 "mesh's subdomain IDs for the expected behavior.");
64 _void_sids.insert(sid);
65 }
66 return lower_bound_id;
67 }
68 return sid;
69}
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition MooseError.h:345
registerMooseObject("MooseApp", VariableValueElementSubdomainModifier)
void ErrorVector unsigned int
static InputParameters validParams()
const QBase *const & _qrule
const MooseArray< Real > & _coord
const MooseArray< Real > & _JxW
const Real & _current_elem_volume
The current element volume (available during execute())
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 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::set< SubdomainID > & meshSubdomains() const
Returns a read-only reference to the set of subdomains currently present in the Mesh.
Definition MooseMesh.C:3272
This user object modifies the element subdomain ID based on the provided variable value.
VariableValueElementSubdomainModifier(const InputParameters &parameters)
virtual SubdomainID computeSubdomainID() override
Compute the subdomain ID of the current element.