https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SidesetInfoVectorPostprocessor.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#include <limits>
12
13#include "libmesh/quadrature.h"
14
16
19{
21 MultiMooseEnum meta_data_types("centroid=0 min=1 max=2 area=3");
23 "meta_data_types", meta_data_types, "Data types that are obtained and written to file.");
24 params.addClassDescription("This VectorPostprocessor collects meta data for provided sidesets.");
25 return params;
26}
27
29 : SideVectorPostprocessor(parameters),
30 _meta_data_types(getParam<MultiMooseEnum>("meta_data_types")),
31 _sideset_ids(declareVector("Boundary IDs"))
32{
33 // this sets up the _vpp_entry_names vector
34 for (unsigned int j = 0; j < _meta_data_types.size(); ++j)
35 {
36 if (_meta_data_types[j] == "centroid" || _meta_data_types[j] == "min" ||
37 _meta_data_types[j] == "max")
38 {
39 for (unsigned int d = 0; d < _mesh.dimension(); ++d)
40 {
41 std::stringstream ss;
42 ss << _meta_data_types[j] << "_";
43 if (d == 0)
44 ss << "x";
45 else if (d == 1)
46 ss << "y";
47 else if (d == 2)
48 ss << "z";
50 }
51 }
52 else
54 }
55
56 // now we can initialize the _meta_data vector
57 _meta_data.resize(_vpp_entry_names.size());
58 for (unsigned int j = 0; j < _vpp_entry_names.size(); ++j)
60}
61
62void
64{
65 // Clear existing data
66 _sideset_ids.clear();
67 for (unsigned int j = 0; j < _vpp_entry_names.size(); ++j)
68 _meta_data[j]->clear();
69
70 for (auto & e : boundaryIDs())
72
73 // resize containers for possibly new number of boundaries
75 for (unsigned int j = 0; j < _vpp_entry_names.size(); ++j)
76 _meta_data[j]->resize(numBoundaryIDs());
77}
78
79void
81{
82 mooseAssert(_boundary_data.find(_current_boundary_id) != _boundary_data.end(),
83 "_current_boundary_id not found in _boundary_data.");
84
85 auto & bd = _boundary_data.find(_current_boundary_id)->second;
86 bd.area += _current_side_volume;
87 bd.centroid += _current_side_elem->vertex_average() * _current_side_volume;
88
89 BoundingBox box = _current_side_elem->loose_bounding_box();
90 Point lmin = box.min();
91 Point lmax = box.max();
92
93 for (unsigned int j = 0; j < 3; ++j)
94 {
95 if (lmin(j) < bd.min(j))
96 bd.min(j) = lmin(j);
97
98 if (lmax(j) > bd.max(j))
99 bd.max(j) = lmax(j);
100 }
101}
102
103void
105{
106 for (auto & e : _boundary_data)
107 {
108 auto & bd = e.second;
109 gatherSum(bd.area);
110 for (unsigned int j = 0; j < 3; ++j)
111 {
112 gatherMin(bd.min(j));
113 gatherMax(bd.max(j));
114 gatherSum(bd.centroid(j));
115 }
116 }
117
118 // centroid needs to be divided by area
119 for (auto & e : _boundary_data)
120 e.second.centroid /= e.second.area;
121
122 // fill vectors
123 unsigned int j = 0;
124 for (auto & e : _boundary_data)
125 {
126 // store away the sideset id first
127 _sideset_ids[j] = e.first;
128
129 // now work through the _vpp_entry_names vector
130 for (unsigned int i = 0; i < _vpp_entry_names.size(); ++i)
131 (*_meta_data[i])[j] = dataHelper(e.first, _vpp_entry_names[i]);
132
133 // increment counter
134 ++j;
135 }
136}
137
138void
140{
141 const auto & vpp = static_cast<const SidesetInfoVectorPostprocessor &>(y);
142
143 for (auto & e : _boundary_data)
144 {
145 mooseAssert(vpp._boundary_data.find(e.first) != vpp._boundary_data.end(),
146 "Boundary not found in threadJoin");
147 auto & vpp_bd = vpp._boundary_data.find(e.first)->second;
148 auto & bd = e.second;
149
150 bd.area += vpp_bd.area;
151 bd.centroid += vpp_bd.centroid;
152
153 for (unsigned int j = 0; j < 3; ++j)
154 {
155 if (vpp_bd.min(j) < bd.min(j))
156 bd.min(j) = vpp_bd.min(j);
157
158 if (vpp_bd.max(j) > bd.max(j))
159 bd.max(j) = vpp_bd.max(j);
160 }
161 }
162}
163
164Real
166{
167 mooseAssert(_boundary_data.find(bid) != _boundary_data.end(),
168 "boundary id not found in _boundary_data.");
169
170 auto & bd = _boundary_data.find(bid)->second;
171
172 if (mdat_tpe == "centroid_x")
173 return bd.centroid(0);
174 else if (mdat_tpe == "centroid_y")
175 return bd.centroid(1);
176 else if (mdat_tpe == "centroid_z")
177 return bd.centroid(2);
178 else if (mdat_tpe == "min_x")
179 return bd.min(0);
180 else if (mdat_tpe == "min_y")
181 return bd.min(1);
182 else if (mdat_tpe == "min_z")
183 return bd.min(2);
184 else if (mdat_tpe == "max_x")
185 return bd.max(0);
186 else if (mdat_tpe == "max_y")
187 return bd.max(1);
188 else if (mdat_tpe == "max_z")
189 return bd.max(2);
190 else if (mdat_tpe == "area")
191 return bd.area;
192 else
193 mooseError("meta_data_type not recognized. This should never happen.");
194}
boundary_id_type BoundaryID
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
sideset clear()
registerMooseObject("MooseApp", SidesetInfoVectorPostprocessor)
virtual const std::set< BoundaryID > & boundaryIDs() const
Return the boundary IDs for this object.
unsigned int numBoundaryIDs() const
Return the number of boundaries for this object.
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.
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh me...
Definition MooseMesh.C:2986
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
void push_back(const std::string &names)
Insert operators Operator to insert (push_back) values into the enum.
unsigned int size() const
Return the number of active items in the MultiMooseEnum.
const Real & _current_side_volume
MooseMesh & _mesh
const Elem *const & _current_side_elem
const BoundaryID & _current_boundary_id
static InputParameters validParams()
Computes and outputs information (area, centroid, bounding box) about sidesets.
VectorPostprocessorValue & _sideset_ids
the sideset id
SidesetInfoVectorPostprocessor(const InputParameters &parameters)
std::map< BoundaryID, BoundaryData > _boundary_data
all data available through the meta_data_types is always accumulated
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
virtual void threadJoin(const UserObject &y) override
Must override.
virtual void finalize() override
Finalize.
MultiMooseEnum _meta_data_types
the type of meta data that is written to file
Real dataHelper(BoundaryID bid, std::string mdat_tpe) const
a helper function for retrieving data from _boundary_info
virtual void execute() override
Execute method.
std::vector< VectorPostprocessorValue * > _meta_data
the vpp data is stored here
std::vector< std::string > _vpp_entry_names
the type of meta data that is written to file
void gatherSum(T &value)
Gather the parallel sum of the variable passed in.
void gatherMin(T &value)
Gather the parallel min of the variable passed in.
void gatherMax(T &value)
Gather the parallel max of the variable passed in.
Base class for user-specific data.
Definition UserObject.h:20
VectorPostprocessorValue & declareVector(const std::string &vector_name)
Register a new vector to fill up.