Line data Source code
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 : 28 : /** 29 : * Global for adding ambient convection parameters 30 : */ 31 : void addAmbientConvectionParams(InputParameters & params); 32 : 33 : /** 34 : * Object for tracking what kernels have been added to an INSAD simulation. This is used to 35 : * determine what properties to calculate in the INSADMaterial, which is important particularly for 36 : * ensuring that we have consistenly included all the strong terms for stabilization methods like 37 : * PSPG and SUPG 38 : */ 39 : class INSADObjectTracker : public GeneralUserObject 40 : { 41 : public: 42 : static InputParameters validParams(); 43 : 44 : INSADObjectTracker(const InputParameters & parameters); 45 : 46 : /** 47 : * Set the internal parameter \p name to \p value. This will check whether \p name has already 48 : * been set and if so, it will whether the old and new values are consistent. If they are not, 49 : * then we will error 50 : */ 51 : template <typename T> 52 : void set(const std::string & name, const T & value, SubdomainID sub_id); 53 : 54 : /** 55 : * Get the internal parameter \p name. This will check whether \p name has already 56 : * been set by the user. If it has not, then we will error 57 : */ 58 : template <typename T> 59 : const T & get(const std::string & name, SubdomainID sub_id) const; 60 : 61 1780 : virtual void initialize() final {} 62 1780 : virtual void execute() final {} 63 1780 : virtual void finalize() final {} 64 : 65 : bool isTrackerParamValid(const std::string & name, SubdomainID sub_id) const; 66 : 67 : /** 68 : * Add additional block coverage to this 69 : */ 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 : 78 : static InputParameters validTrackerParams(); 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 643 : 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 6169 : INSADObjectTracker::set(const std::string & name, const T & value, InputParameters & params) 99 : { 100 6169 : if (params.isParamSetByUser(name)) 101 : { 102 1263 : const T & current_value = params.get<T>(name); 103 1106 : if (INSADObjectTracker::notEqual(current_value, value)) 104 0 : ::mooseError("Two INSADObjects set different values for the parameter ", name); 105 : } 106 4906 : else if (!params.have_parameter<T>(name)) 107 0 : ::mooseError("Attempting to set parameter ", name, " that is not a valid param"); 108 : else 109 4906 : params.set<T>(name) = value; 110 6169 : } 111 : 112 : template <typename T> 113 : void 114 6169 : INSADObjectTracker::set(const std::string & name, const T & value, const SubdomainID sub_id) 115 : { 116 6169 : INSADObjectTracker::set(name, value, const_cast<InputParameters &>(getParams(sub_id))); 117 6169 : } 118 : 119 : template <typename T> 120 : const T & 121 5654677 : INSADObjectTracker::get(const std::string & name, const SubdomainID sub_id) const 122 : { 123 5654677 : const InputParameters & params = getParams(sub_id); 124 : 125 5654677 : if (!params.isParamValid(name)) 126 0 : mooseError("The parameter ", name, " is being retrieved before being set"); 127 : 128 5654677 : return params.get<T>(name); 129 : }