https://mooseframework.inl.gov
Loading...
Searching...
No Matches
AddMetaDataGenerator.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
12#include "MooseMeshUtils.h"
13#include "CastUniquePointer.h"
14
15#include "libmesh/boundary_info.h"
16
18
21{
23
25 "This mesh generator assigns extraneous mesh metadata to the input mesh");
26 params.addParam<MeshGeneratorName>("input", "The mesh we want to modify");
27
28 params.addParam<std::vector<std::string>>(
29 "real_scalar_metadata_names", {}, "Names of the real scalar mesh metadata.");
30 params.addParam<std::vector<Real>>(
31 "real_scalar_metadata_values", {}, "Values of the real scalar mesh metadata.");
32 params.addParam<std::vector<std::string>>(
33 "uint_scalar_metadata_names", {}, "Names of the unsigned integer scalar mesh metadata.");
34 params.addParam<std::vector<unsigned int>>(
35 "uint_scalar_metadata_values", {}, "Values of the unsigned integer scalar mesh metadata.");
36 params.addParam<std::vector<std::string>>(
37 "int_scalar_metadata_names", {}, "Names of the integer scalar mesh metadata.");
38 params.addParam<std::vector<int>>(
39 "int_scalar_metadata_values", {}, "Values of the integer scalar mesh metadata.");
40 params.addParam<std::vector<std::string>>(
41 "dof_id_type_scalar_metadata_names", {}, "Names of the dof_id_type scalar mesh metadata.");
42 params.addParam<std::vector<dof_id_type>>(
43 "dof_id_type_scalar_metadata_values", {}, "Values of the dof_id_type scalar mesh metadata.");
44 params.addParam<std::vector<std::string>>("subdomain_id_type_scalar_metadata_names",
45 {},
46 "Names of the subdomain_id_type scalar mesh metadata.");
47 params.addParam<std::vector<subdomain_id_type>>(
48 "subdomain_id_type_scalar_metadata_values",
49 {},
50 "Values of the subdomain_id_type scalar mesh metadata.");
51 params.addParam<std::vector<std::string>>(
52 "boolean_scalar_metadata_names", {}, "Names of the boolean scalar mesh metadata.");
53 params.addParam<std::vector<bool>>(
54 "boolean_scalar_metadata_values", {}, "Values of the boolean scalar mesh metadata.");
55 params.addParam<std::vector<std::string>>(
56 "point_scalar_metadata_names", {}, "Names of the point scalar mesh metadata.");
57 params.addParam<std::vector<Point>>(
58 "point_scalar_metadata_values", {}, "Values of the point scalar mesh metadata.");
59
60 params.addParam<std::vector<std::string>>(
61 "real_vector_metadata_names", {}, "Names of the real vector mesh metadata.");
62 params.addParam<std::vector<std::vector<Real>>>(
63 "real_vector_metadata_values", {}, "Values of the real vector mesh metadata.");
64 params.addParam<std::vector<std::string>>(
65 "uint_vector_metadata_names", {}, "Names of the unsigned integer vector mesh metadata.");
66 params.addParam<std::vector<std::vector<unsigned int>>>(
67 "uint_vector_metadata_values", {}, "Values of the unsigned integer vector mesh metadata.");
68 params.addParam<std::vector<std::string>>(
69 "int_vector_metadata_names", {}, "Names of the integer vector mesh metadata.");
70 params.addParam<std::vector<std::vector<int>>>(
71 "int_vector_metadata_values", {}, "Values of the integer vector mesh metadata.");
72 params.addParam<std::vector<std::string>>(
73 "dof_id_type_vector_metadata_names", {}, "Names of the dof_id_type vector mesh metadata.");
74 params.addParam<std::vector<std::vector<dof_id_type>>>(
75 "dof_id_type_vector_metadata_values", {}, "Values of the dof_id_type vector mesh metadata.");
76 params.addParam<std::vector<std::string>>("subdomain_id_type_vector_metadata_names",
77 {},
78 "Names of the subdomain_id_type vector mesh metadata.");
79 params.addParam<std::vector<std::vector<subdomain_id_type>>>(
80 "subdomain_id_type_vector_metadata_values",
81 {},
82 "Values of the subdomain_id_type vector mesh metadata.");
83 params.addParam<std::vector<std::string>>(
84 "point_vector_metadata_names", {}, "Names of the Point vector mesh metadata.");
85 params.addParam<std::vector<std::vector<Point>>>(
86 "point_vector_metadata_values", {}, "Values of the Point vector mesh metadata.");
87
88 // This generator only adds data in its constructor, so it's safe to do this
90
91 return params;
92}
93
95 : MeshGenerator(parameters),
96 _input(isParamValid("input") ? &getMesh("input") : nullptr),
97 _real_scalar_metadata_names(getParam<std::vector<std::string>>("real_scalar_metadata_names")),
98 _real_scalar_metadata_values(getParam<std::vector<Real>>("real_scalar_metadata_values")),
99 _uint_scalar_metadata_names(getParam<std::vector<std::string>>("uint_scalar_metadata_names")),
100 _uint_scalar_metadata_values(
101 getParam<std::vector<unsigned int>>("uint_scalar_metadata_values")),
102 _int_scalar_metadata_names(getParam<std::vector<std::string>>("int_scalar_metadata_names")),
103 _int_scalar_metadata_values(getParam<std::vector<int>>("int_scalar_metadata_values")),
104 _dof_id_type_scalar_metadata_names(
105 getParam<std::vector<std::string>>("dof_id_type_scalar_metadata_names")),
106 _dof_id_type_scalar_metadata_values(
107 getParam<std::vector<dof_id_type>>("dof_id_type_scalar_metadata_values")),
108 _subdomain_id_type_scalar_metadata_names(
109 getParam<std::vector<std::string>>("subdomain_id_type_scalar_metadata_names")),
110 _subdomain_id_type_scalar_metadata_values(
111 getParam<std::vector<subdomain_id_type>>("subdomain_id_type_scalar_metadata_values")),
112 _boolean_scalar_metadata_names(
113 getParam<std::vector<std::string>>("boolean_scalar_metadata_names")),
114 _boolean_scalar_metadata_values(getParam<std::vector<bool>>("boolean_scalar_metadata_values")),
115 _point_scalar_metadata_names(getParam<std::vector<std::string>>("point_scalar_metadata_names")),
116 _point_scalar_metadata_values(getParam<std::vector<Point>>("point_scalar_metadata_values")),
117 _real_vector_metadata_names(getParam<std::vector<std::string>>("real_vector_metadata_names")),
118 _real_vector_metadata_values(
119 getParam<std::vector<std::vector<Real>>>("real_vector_metadata_values")),
120 _uint_vector_metadata_names(getParam<std::vector<std::string>>("uint_vector_metadata_names")),
121 _uint_vector_metadata_values(
122 getParam<std::vector<std::vector<unsigned int>>>("uint_vector_metadata_values")),
123 _int_vector_metadata_names(getParam<std::vector<std::string>>("int_vector_metadata_names")),
124 _int_vector_metadata_values(
125 getParam<std::vector<std::vector<int>>>("int_vector_metadata_values")),
126 _dof_id_type_vector_metadata_names(
127 getParam<std::vector<std::string>>("dof_id_type_vector_metadata_names")),
128 _dof_id_type_vector_metadata_values(
129 getParam<std::vector<std::vector<dof_id_type>>>("dof_id_type_vector_metadata_values")),
130 _subdomain_id_type_vector_metadata_names(
131 getParam<std::vector<std::string>>("subdomain_id_type_vector_metadata_names")),
132 _subdomain_id_type_vector_metadata_values(getParam<std::vector<std::vector<subdomain_id_type>>>(
133 "subdomain_id_type_vector_metadata_values")),
134 _point_vector_metadata_names(getParam<std::vector<std::string>>("point_vector_metadata_names")),
135 _point_vector_metadata_values(
136 getParam<std::vector<std::vector<Point>>>("point_vector_metadata_values"))
137{
139 for (unsigned int i = 0; i < _real_scalar_metadata_names.size(); i++)
140 declareMeshProperty<Real>(_real_scalar_metadata_names[i], _real_scalar_metadata_values[i]);
141
143 for (unsigned int i = 0; i < _uint_scalar_metadata_names.size(); i++)
144 declareMeshProperty<unsigned int>(_uint_scalar_metadata_names[i],
146
148 for (unsigned int i = 0; i < _int_scalar_metadata_names.size(); i++)
149 declareMeshProperty<int>(_int_scalar_metadata_names[i], _int_scalar_metadata_values[i]);
150
153 "dof_id_type_scalar");
154 for (unsigned int i = 0; i < _dof_id_type_scalar_metadata_names.size(); i++)
155 declareMeshProperty<dof_id_type>(_dof_id_type_scalar_metadata_names[i],
157
160 "subdomain_id_type_scalar");
161 for (unsigned int i = 0; i < _subdomain_id_type_scalar_metadata_names.size(); i++)
162 declareMeshProperty<subdomain_id_type>(_subdomain_id_type_scalar_metadata_names[i],
164
166 for (unsigned int i = 0; i < _boolean_scalar_metadata_names.size(); i++)
167 declareMeshProperty<bool>(_boolean_scalar_metadata_names[i],
169
171 for (unsigned int i = 0; i < _point_scalar_metadata_names.size(); i++)
172 declareMeshProperty<Point>(_point_scalar_metadata_names[i], _point_scalar_metadata_values[i]);
173
175 for (unsigned int i = 0; i < _real_vector_metadata_names.size(); i++)
178
180 for (unsigned int i = 0; i < _uint_vector_metadata_names.size(); i++)
181 declareMeshProperty<std::vector<unsigned int>>(_uint_vector_metadata_names[i],
183
185 for (unsigned int i = 0; i < _int_vector_metadata_names.size(); i++)
188
191 "dof_id_type_vector");
192 for (unsigned int i = 0; i < _dof_id_type_vector_metadata_names.size(); i++)
193 declareMeshProperty<std::vector<dof_id_type>>(_dof_id_type_vector_metadata_names[i],
195
198 "subdomain_id_type_vector");
199 for (unsigned int i = 0; i < _subdomain_id_type_vector_metadata_names.size(); i++)
200 declareMeshProperty<std::vector<subdomain_id_type>>(
202
204 for (unsigned int i = 0; i < _point_vector_metadata_names.size(); i++)
207}
208
209std::unique_ptr<MeshBase>
211{
212 if (!isParamValid("input"))
213 paramError("input", "Input was not specified");
214
215 mooseAssert(_input, "Should be set");
216 std::unique_ptr<MeshBase> mesh = std::move(*_input);
217 return dynamic_pointer_cast<MeshBase>(mesh);
218}
219
220void
222{
223 // We don't need to do anything here because all data is generated in the constructor
224}
225
226template <class T>
227void
228AddMetaDataGenerator::inputChecker(const std::vector<std::string> data_names,
229 const std::vector<T> data_values,
230 const std::string param_name)
231{
232 std::vector<std::string> data_name_tmp(data_names);
233 if (std::unique(data_name_tmp.begin(), data_name_tmp.end()) != data_name_tmp.end())
234 paramError(param_name + "_metadata_names", "Elements of this parameter must be unique.");
235 if (data_names.size() != data_values.size())
236 paramError(param_name + "_metadata_values",
237 "Length of this parameter must be the same as that of " + param_name +
238 "_metadata_names");
239}
registerMooseObject("MooseApp", AddMetaDataGenerator)
void ErrorVector unsigned int
This mesh generator assigns external mesh metadata to the input mesh.
const std::vector< std::string > _int_vector_metadata_names
List of mesh metadata names for the integer type vectors.
const std::vector< dof_id_type > _dof_id_type_scalar_metadata_values
List of mesh metadata values for the dof_id_type type scalars.
const std::vector< std::string > _real_vector_metadata_names
List of mesh metadata names for the Real type vectors.
const std::vector< std::string > _subdomain_id_type_scalar_metadata_names
List of mesh metadata names for the subdomain_id_type type scalars.
virtual std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
const std::vector< bool > _boolean_scalar_metadata_values
List of mesh metadata values for the boolean type scalars.
const std::vector< std::string > _point_vector_metadata_names
List of mesh metadata names for the Point type vectors.
virtual void generateData() override
Generate the mesh data.
const std::vector< std::string > _int_scalar_metadata_names
List of mesh metadata names for the integer type scalars.
std::unique_ptr< MeshBase > * _input
The input mesh to add the mesh metadata to (when not doing data-only)
const std::vector< std::string > _uint_scalar_metadata_names
List of mesh metadata names for the unsigned integer type scalars.
const std::vector< std::string > _dof_id_type_scalar_metadata_names
List of mesh metadata names for the dof_id_type type scalars.
const std::vector< std::vector< int > > _int_vector_metadata_values
List of mesh metadata values for the integer type vectors.
const std::vector< subdomain_id_type > _subdomain_id_type_scalar_metadata_values
List of mesh metadata values for the subdomain_id_type type scalars.
AddMetaDataGenerator(const InputParameters &parameters)
void inputChecker(const std::vector< std::string > data_names, const std::vector< T > data_values, const std::string param_name)
Check the sanity of a pair of input parameters.
const std::vector< unsigned int > _uint_scalar_metadata_values
List of mesh metadata values for the unsigned integer type scalars.
static InputParameters validParams()
const std::vector< std::string > _subdomain_id_type_vector_metadata_names
List of mesh metadata names for the subdomain_id_type type vectors.
const std::vector< std::vector< Point > > _point_vector_metadata_values
List of mesh metadata values for the Point type vectors.
const std::vector< std::string > _point_scalar_metadata_names
List of mesh metadata names for single Point metadata.
const std::vector< std::vector< subdomain_id_type > > _subdomain_id_type_vector_metadata_values
List of mesh metadata values for the subdomain_id_type type vectors.
const std::vector< std::string > _real_scalar_metadata_names
List of mesh metadata names for the Real type scalars.
const std::vector< std::string > _dof_id_type_vector_metadata_names
List of mesh metadata names for the dof_id_type type vectors.
const std::vector< Point > _point_scalar_metadata_values
List of mesh metadata values for single Point metadata.
const std::vector< std::vector< unsigned int > > _uint_vector_metadata_values
List of mesh metadata values for the unsigned integer type vectors.
const std::vector< std::string > _boolean_scalar_metadata_names
List of mesh metadata names for the boolean type scalars.
const std::vector< std::vector< Real > > _real_vector_metadata_values
List of mesh metadata values for the Real type vectors.
const std::vector< int > _int_scalar_metadata_values
List of mesh metadata values for the integer type scalars.
const std::vector< Real > _real_scalar_metadata_values
List of mesh metadata values for the Real type scalars.
const std::vector< std::vector< dof_id_type > > _dof_id_type_vector_metadata_values
List of mesh metadata values for the dof_id_type type vectors.
const std::vector< std::string > _uint_vector_metadata_names
List of mesh metadata names for the unsigned integer type vectors.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
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.
MeshGenerators are objects that can modify or add to an existing mesh.
static InputParameters validParams()
static void setHasGenerateData(InputParameters &params)
Sets that a mesh generator has a generateData() implementation.
T & declareMeshProperty(const std::string &data_name, Args &&... args)
Methods for writing out attributes to the mesh meta-data store, which can be retrieved from most othe...
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
MeshBase & mesh