https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MeshInfo.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 "GeneralReporter.h"
13
14#include "libmesh/enum_elem_type.h"
15#include "libmesh/enum_elem_quality.h"
16
17namespace libMesh
18{
19class EquationSystems;
20class System;
21class MeshBase;
22}
28{
29public:
31
33
37 enum BoundType : int
38 {
39 MIN = 0,
40 MAX = 1
41 };
42
47 struct DomainElemQuality : public std::pair<libMesh::ElemQuality, BoundType>
48 {
49 DomainElemQuality() = default;
50 DomainElemQuality(const libMesh::ElemQuality elem_quality, const BoundType bound_type);
51
54 libMesh::ElemQuality & elemQuality() { return this->first; }
55 const libMesh::ElemQuality & elemQuality() const { return this->first; }
57
60 BoundType & boundType() { return this->second; }
61 const BoundType & boundType() const { return this->second; }
63
65 std::string itemName() const;
67 void updateValue(std::map<DomainElemQuality, Real> & quality_map, const Real value) const;
68 };
69
72 static const std::vector<DomainElemQuality> domain_elem_qualities;
74 static const std::vector<libMesh::ElemQuality> elem_qualities;
75
81 template <typename IDType>
82 struct InfoBase
83 {
84 using id_type = IDType;
85
86 InfoBase() = default;
87 InfoBase(const IDType id) : id(id) {}
88
90 IDType id;
91 };
92
98 template <typename IDType>
99 struct ElemContainingInfo : public InfoBase<IDType>
100 {
102 ElemContainingInfo(const IDType id) : InfoBase<IDType>(id) {}
103
104 // Bounding box
105 BoundingBox bounding_box;
106 // Total volume
107 Real volume = 0;
108 };
109
116 template <typename IDType, typename ElemsType>
117 struct DomainInfo : public ElemContainingInfo<IDType>
118 {
119 DomainInfo() = default;
120 DomainInfo(const IDType id) : ElemContainingInfo<IDType>(id) {}
121
123 std::string name;
125 std::map<DomainElemQuality, Real> elem_qualities;
127 std::vector<ElemsType> elems;
129 std::set<libMesh::ElemType> elem_types;
131 Real min_volume = std::numeric_limits<Real>::max();
133 Real max_volume = 0;
135 std::size_t num_elems = 0;
137 std::set<processor_id_type> processor_ids;
138 };
143
147 struct ElemInfo : public ElemContainingInfo<dof_id_type>
148 {
149 ElemInfo() = default;
150 ElemInfo(const dof_id_type id, const SubdomainID subdomain_id)
152 {
153 }
154
158 std::vector<std::pair<libMesh::ElemQuality, Real>> elem_qualities;
160 unsigned short dim;
166 Real hmax;
168 Real hmin;
170 std::vector<dof_id_type> neighbor_ids;
172 std::vector<dof_id_type> node_ids;
174 unsigned int num_sides;
176 std::vector<Point> points;
178 processor_id_type processor_id;
180 unique_id_type unique_id;
181 };
182
188 {
191
194 bool bounding_box = false;
195 bool volume = false;
197 };
198
203 {
204 DomainInfoItems() = default;
206
209 bool elems = false;
210 bool elem_types = false;
211 bool max_volume = false;
212 bool min_volume = false;
213 bool num_elems = false;
214 bool processor_ids = false;
216
218 std::vector<DomainElemQuality> elem_qualities;
219 };
220
222 {
223 ElemInfoItems() = default;
225
228 bool dim = false;
229 bool elem_mapping_type = false;
230 bool elem_type = false;
231 bool hmax = false;
232 bool hmin = false;
233 bool neighbor_ids = false;
234 bool node_ids = false;
235 bool num_sides = false;
236 bool points = false;
237 bool processor_id = false;
238 bool unique_id = false;
241 std::vector<libMesh::ElemQuality> elem_qualities;
242 };
243
251 template <class InfoType, class ItemsType>
252 struct InfoMap
253 {
254 using id_type = typename InfoType::id_type;
255 using info_type = InfoType;
256 using map_type = std::map<id_type, InfoType>;
257
258 InfoMap() = default;
259 InfoMap(const ItemsType & items) : items(items) {}
260
264 ItemsType items;
265 };
272
281 template <class InfoMapType, class ItemsType>
283 {
284 using info_map_type = InfoMapType;
285 using id_type = typename InfoMapType::id_type;
286 using info_type = typename InfoMapType::info_type;
287 using map_type = typename info_map_type::map_type;
288 using items_type = ItemsType;
289
291
293 InfoMapType * const local;
295 InfoMapType * const global;
297 const ItemsType items;
298 };
305
306 virtual void initialize() override {}
307 virtual void finalize() override {}
308 virtual void execute() override;
309
310 static bool hasItem(const std::string & name, const MultiMooseEnum & items);
311
312protected:
327
332 template <typename T, typename... Args>
333 T * declareHelper(const std::string & name, const ReporterMode mode, Args &&... args);
334
335private:
337 template <class CombinedInfosType>
338 CombinedInfosType initCombinedInfos(const std::string & name,
339 const MultiMooseEnum & items,
340 const MultiMooseEnum & qualities);
341
343 void possiblyAddElemInfo();
344
346 template <class CombinedInfosType>
347 void possiblyAddDomainInfo(CombinedInfosType & infos);
348
355 unsigned int * const _num_dofs;
356 unsigned int * const _num_dofs_nl;
357 unsigned int * const _num_dofs_aux;
358 unsigned int * const _num_dofs_constrained;
359 unsigned int * const _num_elem;
360 unsigned int * const _num_node;
361 unsigned int * const _num_local_dofs;
362 unsigned int * const _num_local_dofs_nl;
363 unsigned int * const _num_local_dofs_aux;
364 unsigned int * const _num_local_elem;
365 unsigned int * const _num_local_node;
367
374
379};
380
381template <typename T, typename... Args>
382T *
383MeshInfo::declareHelper(const std::string & name, const ReporterMode mode, Args &&... args)
384{
385 return hasItem(name, _items) ? &declareValueByName<T>(name, mode, args...) : nullptr;
386}
387
392void to_json(nlohmann::json &, const MeshInfo::ElemInfoMap &);
393void to_json(nlohmann::json &, const MeshInfo::SidesetInfoMap &);
394void to_json(nlohmann::json &, const MeshInfo::SubdomainInfoMap &);
396
401void dataStore(std::ostream &, MeshInfo::DomainElemQuality &, void *);
402void dataLoad(std::istream &, MeshInfo::DomainElemQuality &, void *);
404
409void dataStore(std::ostream &, MeshInfo::ElemInfo &, void *);
410void dataStore(std::ostream &, MeshInfo::SidesetInfo &, void *);
411void dataStore(std::ostream &, MeshInfo::SubdomainInfo &, void *);
412void dataLoad(std::istream &, MeshInfo::ElemInfo &, void *);
413void dataLoad(std::istream &, MeshInfo::SidesetInfo &, void *);
414void dataLoad(std::istream &, MeshInfo::SubdomainInfo &, void *);
416
421void dataStore(std::ostream &, MeshInfo::ElemInfoMap &, void *);
422void dataStore(std::ostream &, MeshInfo::SidesetInfoMap &, void *);
423void dataStore(std::ostream &, MeshInfo::SubdomainInfoMap &, void *);
424void dataLoad(std::istream &, MeshInfo::ElemInfoMap &, void *);
425void dataLoad(std::istream &, MeshInfo::SidesetInfoMap &, void *);
426void dataLoad(std::istream &, MeshInfo::SubdomainInfoMap &, void *);
void dataStore(std::ostream &, MeshInfo::DomainElemQuality &, void *)
Data store and load for DomainElemQuality.
Definition MeshInfo.C:861
void to_json(nlohmann::json &, const MeshInfo::ElemInfoMap &)
JSON serialization for info maps.
Definition MeshInfo.C:747
void dataLoad(std::istream &, MeshInfo::DomainElemQuality &, void *)
Definition MeshInfo.C:872
Reporter object that has a single execution of the "execute" method for each execute flag.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Report mesh information, such as the number of elements, nodes, and degrees of freedom.
Definition MeshInfo.h:28
unsigned int *const _num_dofs_constrained
Definition MeshInfo.h:358
static bool hasItem(const std::string &name, const MultiMooseEnum &items)
Definition MeshInfo.C:698
unsigned int *const _num_local_dofs_aux
Definition MeshInfo.h:363
SidesetInfos _sideset_infos
Combined sideset information (reporter values and requested items)
Definition MeshInfo.h:371
unsigned int *const _num_dofs_aux
Definition MeshInfo.h:357
const libMesh::System & _aux_system
Definition MeshInfo.h:377
static InputParameters validParams()
Definition MeshInfo.C:40
const MultiMooseEnum & _sideset_elem_qualities
The requested element quality metrics, bounded over sidesets.
Definition MeshInfo.h:324
const MultiMooseEnum & _elem_qualities
The requested element quality metrics.
Definition MeshInfo.h:322
unsigned int *const _num_local_node
Definition MeshInfo.h:365
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
Definition MeshInfo.h:306
BoundType
Type of a bound for DomainElemQuality (min or max).
Definition MeshInfo.h:38
const MultiMooseEnum & _sideset_items
The requested sideset items.
Definition MeshInfo.h:318
ElemInfos _elem_infos
Combined element information (reporter values and requested items)
Definition MeshInfo.h:369
static const std::vector< libMesh::ElemQuality > elem_qualities
The qualities to include for elems.
Definition MeshInfo.h:29
CombinedInfosType initCombinedInfos(const std::string &name, const MultiMooseEnum &items, const MultiMooseEnum &qualities)
Initializer for SidesetInfos and SubdomainInfos.
Definition MeshInfo.C:253
const MultiMooseEnum & _subdomain_elem_qualities
The requested element quality metrics, bounded over subdomains.
Definition MeshInfo.h:326
unsigned int *const _num_dofs
Reporter values to declare.
Definition MeshInfo.h:355
T * declareHelper(const std::string &name, const ReporterMode mode, Args &&... args)
Helper to perform optional declaration based on if the item is requested or all are requested.
Definition MeshInfo.h:383
const libMesh::MeshBase & _mesh
Definition MeshInfo.h:378
const MultiMooseEnum & _items
The requested items.
Definition MeshInfo.h:314
unsigned int *const _num_local_dofs_nl
Definition MeshInfo.h:362
const MultiMooseEnum & _subdomain_items
The requested subdomain items.
Definition MeshInfo.h:320
const libMesh::EquationSystems & _equation_systems
Definition MeshInfo.h:375
virtual void finalize() override
Finalize.
Definition MeshInfo.h:307
virtual void execute() override
Execute method.
Definition MeshInfo.C:666
unsigned int *const _num_node
Definition MeshInfo.h:360
const libMesh::System & _nonlinear_system
Definition MeshInfo.h:376
unsigned int *const _num_elem
Definition MeshInfo.h:359
void possiblyAddElemInfo()
Add elem information if requested.
Definition MeshInfo.C:266
unsigned int *const _num_local_dofs
Definition MeshInfo.h:361
void possiblyAddDomainInfo(CombinedInfosType &infos)
Add domain information (sidesets and subdomains) if requested.
Definition MeshInfo.C:439
static const std::vector< DomainElemQuality > domain_elem_qualities
The qualities (ElemQuality and bound type) to include for domain quantities (subdomains and sidesets)
Definition MeshInfo.h:23
SubdomainInfos _subdomain_infos
Combined subdomain information (reporter values and requested items)
Definition MeshInfo.h:373
const MultiMooseEnum & _elem_items
The requested elem items.
Definition MeshInfo.h:316
unsigned int *const _num_local_elem
Definition MeshInfo.h:364
unsigned int *const _num_dofs_nl
Definition MeshInfo.h:356
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
MooseEnumItem that automatically creates the ID and doesn't allow the ID to be assigned.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
Struct that contains all of the reporter data for a domain type (sideset or subdomain) and the items ...
Definition MeshInfo.h:283
const ItemsType items
Which entries are to be output.
Definition MeshInfo.h:297
typename info_map_type::map_type map_type
Definition MeshInfo.h:287
InfoMapType info_map_type
Definition MeshInfo.h:284
typename InfoMapType::info_type info_type
Definition MeshInfo.h:286
typename InfoMapType::id_type id_type
Definition MeshInfo.h:285
InfoMapType *const global
Global information.
Definition MeshInfo.h:295
InfoMapType *const local
Local information.
Definition MeshInfo.h:293
Key for a libMesh::ElemQuality quality type with a bound (min or max) to be used over an entire domai...
Definition MeshInfo.h:48
void updateValue(std::map< DomainElemQuality, Real > &quality_map, const Real value) const
Update the value in the quality map.
Definition MeshInfo.C:186
libMesh::ElemQuality & elemQuality()
Get the libMesh::ElemQuality entry.
Definition MeshInfo.h:54
const libMesh::ElemQuality & elemQuality() const
Definition MeshInfo.h:55
BoundType & boundType()
Get the type of the bound (min or max)
Definition MeshInfo.h:60
std::string itemName() const
Get the name for this quality ([min,max]_[quality])
Definition MeshInfo.C:179
const BoundType & boundType() const
Definition MeshInfo.h:61
Defines which items are to be output for a domain (sideset or subdomain).
Definition MeshInfo.h:203
bool elems
Markers for whether or not a single item should be output.
Definition MeshInfo.h:209
std::vector< DomainElemQuality > elem_qualities
Bounded (min, max) element quality metrics that should be output.
Definition MeshInfo.h:218
Structure for a single domain entry (sideset or subdomain).
Definition MeshInfo.h:118
Real min_volume
Minimum volume.
Definition MeshInfo.h:131
std::set< processor_id_type > processor_ids
Processors the elements are on.
Definition MeshInfo.h:137
DomainInfo(const IDType id)
Definition MeshInfo.h:120
std::vector< ElemsType > elems
Elements in the domain.
Definition MeshInfo.h:127
Real max_volume
Maximum volume.
Definition MeshInfo.h:133
std::size_t num_elems
Number of elements.
Definition MeshInfo.h:135
std::map< DomainElemQuality, Real > elem_qualities
Bounded (min, max) element quality metrics.
Definition MeshInfo.h:125
std::string name
Name.
Definition MeshInfo.h:123
std::set< libMesh::ElemType > elem_types
Type(s) of elements in the domain.
Definition MeshInfo.h:129
Base struct for defining which items are to be output for a domain that contains elements (elems,...
Definition MeshInfo.h:188
bool bounding_box
Markers for whether or not a single item should be output.
Definition MeshInfo.h:194
Struct for element-containing entries (elem, sideset, subdomain).
Definition MeshInfo.h:100
ElemContainingInfo(const IDType id)
Definition MeshInfo.h:102
std::vector< libMesh::ElemQuality > elem_qualities
Element qualities that should be output.
Definition MeshInfo.h:241
bool dim
Markers for whether or not a single item should be output.
Definition MeshInfo.h:228
Structure for a single elem entry.
Definition MeshInfo.h:148
unique_id_type unique_id
Unique ID of the element.
Definition MeshInfo.h:180
std::vector< std::pair< libMesh::ElemQuality, Real > > elem_qualities
Evaluated element qualities.
Definition MeshInfo.h:158
SubdomainID subdomain_id
The element's subdomain ID.
Definition MeshInfo.h:156
std::vector< dof_id_type > neighbor_ids
The ID of each neighbor (indexed by side)
Definition MeshInfo.h:170
libMesh::ElemType elem_type
The element type.
Definition MeshInfo.h:164
ElemInfo(const dof_id_type id, const SubdomainID subdomain_id)
Definition MeshInfo.h:150
std::vector< Point > points
The element's points.
Definition MeshInfo.h:176
Real hmax
The maximum vertex seperation for the element.
Definition MeshInfo.h:166
libMesh::ElemMappingType elem_mapping_type
The element mapping type.
Definition MeshInfo.h:162
unsigned short dim
The dimensionality of the element.
Definition MeshInfo.h:160
processor_id_type processor_id
The processor ID the element is on.
Definition MeshInfo.h:178
std::vector< dof_id_type > node_ids
The IDs of each node.
Definition MeshInfo.h:172
Real hmin
The minimum vertex seperation for the element.
Definition MeshInfo.h:168
unsigned int num_sides
The number of sides on the element.
Definition MeshInfo.h:174
Base struct for information for a single entry (elem, sideset, subdomain).
Definition MeshInfo.h:83
InfoBase(const IDType id)
Definition MeshInfo.h:87
Struct that defines a domain (sideset or subdomain) map (id -> entities) and the items that should be...
Definition MeshInfo.h:253
typename InfoType::id_type id_type
Definition MeshInfo.h:254
ItemsType items
Which items are to be output.
Definition MeshInfo.h:264
InfoMap(const ItemsType &items)
Definition MeshInfo.h:259
std::map< id_type, InfoType > map_type
Definition MeshInfo.h:256
InfoType info_type
Definition MeshInfo.h:255
map_type map
The underlying data.
Definition MeshInfo.h:262