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 "Action.h" 13 : #include "MaterialData.h" 14 : #include "FEProblemBase.h" 15 : 16 : class MooseObjectAction; 17 : class MaterialBase; 18 : 19 : /** 20 : * Creates AuxVariables and AuxKernels for automatic output of material properties 21 : */ 22 : class MaterialOutputAction : public Action 23 : { 24 : public: 25 : static InputParameters validParams(); 26 : 27 : MaterialOutputAction(const InputParameters & params); 28 : 29 : virtual void act() override; 30 : 31 : /// Meta data describing the setup of an output object 32 : struct OutputMetaData 33 : { 34 : std::string _aux_kernel_name; 35 : std::string _index_symbols; 36 : std::vector<std::string> _param_names; 37 : }; 38 : 39 : protected: 40 : /** 41 : * A function to be overriden by derived actions to handle a set of material property types 42 : */ 43 : virtual std::vector<std::string> materialOutput(const std::string & property_name, 44 : const MaterialBase & material, 45 : bool get_names_only); 46 : 47 : /// Universal output object setup function 48 : std::vector<std::string> outputHelper(const OutputMetaData & metadata, 49 : const std::string & property_name, 50 : const std::string & var_name_base, 51 : const MaterialBase & material, 52 : bool get_names_only); 53 : 54 : /** 55 : * Helper method for testing if the material exists as a block or boundary material 56 : * @tparam T The property type (e.g., REAL) 57 : * @param property_name The name of the property to test 58 : */ 59 : template <typename T> 60 : bool hasProperty(const std::string & property_name); 61 : 62 : /** 63 : * Helper method for testing if the material exists as a block or boundary material 64 : * @tparam T The AD property type (e.g., Real) 65 : * @param property_name The name of the AD property to test 66 : */ 67 : template <typename T> 68 : bool hasADProperty(const std::string & property_name); 69 : 70 : /** 71 : * Helper method for testing if the functor material property exists 72 : * @tparam T The functor property type (e.g., Real) 73 : * @param property_name The name of the property to test 74 : */ 75 : template <typename T> 76 : bool hasFunctorProperty(const std::string & property_name); 77 : 78 : /** 79 : * A method for retrieving and partially filling the InputParameters object for an AuxVariable 80 : * @param type The type of AuxVariable 81 : * @param property_name The property name to associated with that action 82 : * @param variable_name The AuxVariable name to create 83 : * @param material A MaterialBase object containing the property of interest 84 : * 85 : * @return An InputParameter object with common properties added. 86 : */ 87 : InputParameters getParams(const std::string & type, 88 : const std::string & property_name, 89 : const std::string & variable_name, 90 : const MaterialBase & material); 91 : 92 : private: 93 : /// Pointer the MaterialData object storing the block restricted materials 94 : const MaterialData * _block_material_data; 95 : 96 : /// Pointer the MaterialData object storing the boundary restricted materials 97 : const MaterialData * _boundary_material_data; 98 : 99 : /// Map of variable name that contains the blocks to which the variable should be restricted 100 : std::map<std::string, std::set<SubdomainID>> _block_variable_map; 101 : 102 : /// variables for the current MaterialBase object 103 : std::set<std::string> _material_variable_names; 104 : 105 : /// Map of output names and list of variables associated with the output 106 : std::map<OutputName, std::set<std::string>> _material_variable_names_map; 107 : 108 : /// Reference to the OutputWarehouse 109 : OutputWarehouse & _output_warehouse; 110 : 111 : /// Output only on TIMESTEP_END, not on INITIAL? 112 : const bool _output_only_on_timestep_end; 113 : }; 114 : 115 : template <typename T> 116 : bool 117 18320 : MaterialOutputAction::hasProperty(const std::string & property_name) 118 : { 119 29684 : if (_block_material_data->haveProperty<T>(property_name) || 120 11364 : _boundary_material_data->haveProperty<T>(property_name)) 121 7060 : return true; 122 : else 123 11260 : return false; 124 : } 125 : 126 : template <typename T> 127 : bool 128 11260 : MaterialOutputAction::hasADProperty(const std::string & property_name) 129 : { 130 20104 : if (_block_material_data->haveADProperty<T>(property_name) || 131 8844 : _boundary_material_data->haveADProperty<T>(property_name)) 132 2512 : return true; 133 : else 134 8748 : return false; 135 : } 136 : 137 : template <typename T> 138 : bool 139 432 : MaterialOutputAction::hasFunctorProperty(const std::string & property_name) 140 : { 141 432 : return _problem->hasFunctorWithType<T>(property_name, 0); 142 : }