https://mooseframework.inl.gov
INSADObjectTracker.h
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 #pragma once
11 
12 #include "GeneralUserObject.h"
13 #include "MooseTypes.h"
14 #include "MooseEnum.h"
15 #include "MooseError.h"
16 #include "InputParameters.h"
17 
18 #include "libmesh/vector_value.h"
19 
20 #include <unordered_map>
21 #include <set>
22 
23 template <typename>
24 class ADMaterialProperty;
25 template <typename>
26 class MaterialProperty;
27 
32 
40 {
41 public:
43 
45 
51  template <typename T>
52  void set(const std::string & name, const T & value, SubdomainID sub_id);
53 
58  template <typename T>
59  const T & get(const std::string & name, SubdomainID sub_id) const;
60 
61  virtual void initialize() final {}
62  virtual void execute() final {}
63  virtual void finalize() final {}
64 
65  bool isTrackerParamValid(const std::string & name, SubdomainID sub_id) const;
66 
70  void addBlockIDs(const std::set<SubdomainID> & additional_block_ids);
71 
72 private:
73  template <typename T>
74  static bool notEqual(const T & val1, const T & val2);
75 
76  std::unordered_map<SubdomainID, InputParameters> _block_id_to_params;
77 
79 
80  template <typename T>
81  static void set(const std::string & name, const T & value, InputParameters & params);
82 
83  const InputParameters & getParams(SubdomainID sub_id) const;
84 };
85 
86 template <typename T>
87 bool
88 INSADObjectTracker::notEqual(const T & val1, const T & val2)
89 {
90  return val1 != val2;
91 }
92 
93 template <>
94 bool INSADObjectTracker::notEqual(const MooseEnum & val1, const MooseEnum & val2);
95 
96 template <typename T>
97 void
98 INSADObjectTracker::set(const std::string & name, const T & value, InputParameters & params)
99 {
100  if (params.isParamSetByUser(name))
101  {
102  const T & current_value = params.get<T>(name);
103  if (INSADObjectTracker::notEqual(current_value, value))
104  ::mooseError("Two INSADObjects set different values for the parameter ", name);
105  }
106  else if (!params.have_parameter<T>(name))
107  ::mooseError("Attempting to set parameter ", name, " that is not a valid param");
108  else
109  params.set<T>(name) = value;
110 }
111 
112 template <typename T>
113 void
114 INSADObjectTracker::set(const std::string & name, const T & value, const SubdomainID sub_id)
115 {
116  INSADObjectTracker::set(name, value, const_cast<InputParameters &>(getParams(sub_id)));
117 }
118 
119 template <typename T>
120 const T &
121 INSADObjectTracker::get(const std::string & name, const SubdomainID sub_id) const
122 {
123  const InputParameters & params = getParams(sub_id);
124 
125  if (!params.isParamValid(name))
126  mooseError("The parameter ", name, " is being retrieved before being set");
127 
128  return params.get<T>(name);
129 }
static InputParameters validTrackerParams()
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
void set(const std::string &name, const T &value, SubdomainID sub_id)
Set the internal parameter name to value.
static InputParameters validParams()
const InputParameters & getParams(SubdomainID sub_id) const
T & set(const std::string &name, bool quiet_mode=false)
virtual void finalize() final
virtual const std::string & name() const
INSADObjectTracker(const InputParameters &parameters)
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
const T & get(const std::string &name, SubdomainID sub_id) const
Get the internal parameter name.
virtual void execute() final
const std::string name
Definition: Setup.h:20
static bool notEqual(const T &val1, const T &val2)
bool isTrackerParamValid(const std::string &name, SubdomainID sub_id) const
void addAmbientConvectionParams(InputParameters &params)
Global for adding ambient convection parameters.
std::unordered_map< SubdomainID, InputParameters > _block_id_to_params
virtual void initialize() final
bool have_parameter(std::string_view name) const
bool isParamSetByUser(const std::string &name) const
void addBlockIDs(const std::set< SubdomainID > &additional_block_ids)
Add additional block coverage to this.
void mooseError(Args &&... args) const
const InputParameters & parameters() const
Object for tracking what kernels have been added to an INSAD simulation.
bool isParamValid(const std::string &name) const