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 : // MOOSE includes 13 : #include "MooseError.h" 14 : #include "ExecFlagEnum.h" 15 : 16 : // Forward declarations 17 : class InputParameters; 18 : 19 : /** 20 : * A structure for storing the various lists that contain 21 : * the names of the items to be exported. An instance of this 22 : * struct exists for each of the output types (non-linear variables, 23 : * scalar variables, postprocessors, etc.) 24 : * 25 : * @see OutputDataWarehouse 26 : */ 27 : struct OutputData 28 : { 29 : /// A list of all possible outputs 30 : std::set<std::string> available; 31 : 32 : /// User-supplied list of outputs to display 33 : std::set<std::string> show; 34 : 35 : /// User-supplied list of outputs to hide 36 : std::set<std::string> hide; 37 : 38 : /// A list of the outputs to write 39 : std::set<std::string> output; 40 : 41 : /// Clear existing sets for re-initialization 42 : void reset(); 43 : }; 44 : 45 : /** 46 : * In newer versions of Clang calling operator[] on a map with a component that 47 : * has a default constructor is an error, thus utilizing a map directly to store 48 : * a ExecFlagEnum is not possible. 49 : * 50 : * This template class is a map wrapper that provides the basic map-like functionality 51 : * for accessing map types with operator[] by using find internally. It also produces 52 : * an error if the map key does not exists, this it provides a layer of protection not 53 : * available to maps operator[] in general. 54 : * 55 : * This class is used here to create two different warehouse containers below. 56 : * 57 : * @see OutputOnWarehouse OutputDataWarehouse 58 : */ 59 : template <typename T> 60 : class OutputMapWrapper 61 : { 62 : public: 63 : /** 64 : * Constructor 65 : */ 66 482373 : OutputMapWrapper(){}; 67 : 68 : /** 69 : * A map accessor that errors if the key is not found 70 : */ 71 95464906 : T & operator[](const std::string & name) 72 : { 73 : // Locate the map entry, error if it is not found 74 95464906 : typename std::map<std::string, T>::iterator iter = _map.find(name); 75 95464906 : if (iter == _map.end()) 76 0 : mooseError("Unknown map key ", name); 77 95464906 : return iter->second; 78 : } 79 : 80 : ///@{ 81 : /** 82 : * Provide iterator and find access to the underlying map data 83 : */ 84 8766065 : typename std::map<std::string, T>::iterator begin() { return _map.begin(); } 85 73322295 : typename std::map<std::string, T>::iterator end() { return _map.end(); } 86 64556230 : typename std::map<std::string, T>::iterator find(const std::string & name) 87 : { 88 64556230 : return _map.find(name); 89 : } 90 20 : typename std::map<std::string, T>::const_iterator begin() const { return _map.begin(); } 91 129245140 : typename std::map<std::string, T>::const_iterator end() const { return _map.end(); } 92 129287114 : const typename std::map<std::string, T>::const_iterator find(const std::string & name) const 93 : { 94 129287114 : return _map.find(name); 95 : } 96 : ///@} 97 : 98 : /** 99 : * A method for testing of a key exists 100 : */ 101 129245120 : bool contains(const std::string & name) const { return find(name) != end(); } 102 : 103 : protected: 104 : /// Data storage 105 : typename std::map<std::string, T> _map; 106 : }; 107 : 108 : /** 109 : * A helper warehouse class for storing the "execute_on" settings for 110 : * the various output types. 111 : * 112 : * In order to allow for new output types to be defined and to minimize 113 : * the number of member variables the "execute_on" parameter for each of 114 : * the output types (e.g., execute_postprocessors_on) are stored in a map. 115 : * 116 : * This allows for iterative access to these parameters, which makes creating 117 : * generic code (e.g., AdvancedOutput::shouldOutput) possible. However, ExecFlagEnum 118 : * has a private constructor, so calling operator[] on the map is a compile time error. 119 : * 120 : * To get around this and to provide a more robust storage structure, one that will error 121 : * if the wrong output name is given, this warehouse was created. For the purposes of the 122 : * AdvancedOutput object this warehouse functions exactly like a std::map, but provides 123 : * an operator[] that works with ExecFlagEnum and errors if called on an invalid key. 124 : * 125 : * @see OutputMapWrapper OutputDataWarehouse 126 : */ 127 : class OutputOnWarehouse : public OutputMapWrapper<ExecFlagEnum> 128 : { 129 : public: 130 : /** 131 : * Constructor 132 : * @param execute_on The general "execute_on" settings for the object. 133 : * @param parameters The parameters object holding data for the class to use. 134 : */ 135 : OutputOnWarehouse(const ExecFlagEnum & execute_on, const InputParameters & parameters); 136 : }; 137 : 138 : /** 139 : * A helper warehouse for storing OutputData objects for the various output types 140 : * 141 : * To keep syntax consistent and to provide the error checking for accessing invalid map keys 142 : * the OutputMapWrapper is used for accessing the OutputData classes as well. 143 : * 144 : * @see OutputOnWarehouse OutputMapWrapper OutputData 145 : */ 146 : class OutputDataWarehouse : public OutputMapWrapper<OutputData> 147 : { 148 : public: 149 : static InputParameters validParams(); 150 : 151 : /** 152 : * Populate the OutputData structures for all output types that are 'variable' based 153 : */ 154 : OutputDataWarehouse(); 155 : 156 : /** 157 : * False when the show lists for all variables is empty. 158 : * 159 : * When false everything should output. 160 : * @see AdvancedOutput::initOutputList 161 : */ 162 1907912 : bool hasShowList() { return _has_show_list; } 163 : 164 : /** 165 : * Set the show list bool. 166 : * 167 : * This is set to true when the user supplies a show list. 168 : * @see AdvancedOutput::initShowHideLists 169 : */ 170 1916 : void setHasShowList(bool value) { _has_show_list = value; } 171 : 172 : /** 173 : * Clear existing lists for re-initialization 174 : */ 175 : void reset(); 176 : 177 : private: 178 : // True when the input file contains a show/hide list 179 : bool _has_show_list; 180 : };