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 : #include "SidesetInfoVectorPostprocessor.h" 11 : #include <limits> 12 : 13 : #include "libmesh/quadrature.h" 14 : 15 : registerMooseObject("MooseApp", SidesetInfoVectorPostprocessor); 16 : 17 : InputParameters 18 14319 : SidesetInfoVectorPostprocessor::validParams() 19 : { 20 14319 : InputParameters params = SideVectorPostprocessor::validParams(); 21 14319 : MultiMooseEnum meta_data_types("centroid=0 min=1 max=2 area=3"); 22 14319 : params.addParam<MultiMooseEnum>( 23 : "meta_data_types", meta_data_types, "Data types that are obtained and written to file."); 24 14319 : params.addClassDescription("This VectorPostprocessor collects meta data for provided sidesets."); 25 28638 : return params; 26 14319 : } 27 : 28 28 : SidesetInfoVectorPostprocessor::SidesetInfoVectorPostprocessor(const InputParameters & parameters) 29 : : SideVectorPostprocessor(parameters), 30 28 : _meta_data_types(getParam<MultiMooseEnum>("meta_data_types")), 31 56 : _sideset_ids(declareVector("Boundary IDs")) 32 : { 33 : // this sets up the _vpp_entry_names vector 34 140 : for (unsigned int j = 0; j < _meta_data_types.size(); ++j) 35 : { 36 168 : if (_meta_data_types[j] == "centroid" || _meta_data_types[j] == "min" || 37 56 : _meta_data_types[j] == "max") 38 : { 39 252 : for (unsigned int d = 0; d < _mesh.dimension(); ++d) 40 : { 41 168 : std::stringstream ss; 42 168 : ss << _meta_data_types[j] << "_"; 43 168 : if (d == 0) 44 84 : ss << "x"; 45 84 : else if (d == 1) 46 84 : ss << "y"; 47 0 : else if (d == 2) 48 0 : ss << "z"; 49 168 : _vpp_entry_names.push_back(ss.str()); 50 168 : } 51 : } 52 : else 53 28 : _vpp_entry_names.push_back(_meta_data_types[j]); 54 : } 55 : 56 : // now we can initialize the _meta_data vector 57 28 : _meta_data.resize(_vpp_entry_names.size()); 58 224 : for (unsigned int j = 0; j < _vpp_entry_names.size(); ++j) 59 196 : _meta_data[j] = &declareVector(_vpp_entry_names[j]); 60 28 : } 61 : 62 : void 63 26 : SidesetInfoVectorPostprocessor::initialize() 64 : { 65 : // Clear existing data 66 26 : _sideset_ids.clear(); 67 208 : for (unsigned int j = 0; j < _vpp_entry_names.size(); ++j) 68 182 : _meta_data[j]->clear(); 69 : 70 104 : for (auto & e : boundaryIDs()) 71 78 : _boundary_data[e] = BoundaryData(); 72 : 73 : // resize containers for possibly new number of boundaries 74 26 : _sideset_ids.resize(numBoundaryIDs()); 75 208 : for (unsigned int j = 0; j < _vpp_entry_names.size(); ++j) 76 182 : _meta_data[j]->resize(numBoundaryIDs()); 77 26 : } 78 : 79 : void 80 324 : SidesetInfoVectorPostprocessor::execute() 81 : { 82 : mooseAssert(_boundary_data.find(_current_boundary_id) != _boundary_data.end(), 83 : "_current_boundary_id not found in _boundary_data."); 84 : 85 324 : auto & bd = _boundary_data.find(_current_boundary_id)->second; 86 324 : bd.area += _current_side_volume; 87 324 : bd.centroid += _current_side_elem->vertex_average() * _current_side_volume; 88 : 89 324 : BoundingBox box = _current_side_elem->loose_bounding_box(); 90 324 : Point lmin = box.min(); 91 324 : Point lmax = box.max(); 92 : 93 1296 : for (unsigned int j = 0; j < 3; ++j) 94 : { 95 972 : if (lmin(j) < bd.min(j)) 96 192 : bd.min(j) = lmin(j); 97 : 98 972 : if (lmax(j) > bd.max(j)) 99 452 : bd.max(j) = lmax(j); 100 : } 101 324 : } 102 : 103 : void 104 24 : SidesetInfoVectorPostprocessor::finalize() 105 : { 106 96 : for (auto & e : _boundary_data) 107 : { 108 72 : auto & bd = e.second; 109 72 : gatherSum(bd.area); 110 288 : for (unsigned int j = 0; j < 3; ++j) 111 : { 112 216 : gatherMin(bd.min(j)); 113 216 : gatherMax(bd.max(j)); 114 216 : gatherSum(bd.centroid(j)); 115 : } 116 : } 117 : 118 : // centroid needs to be divided by area 119 96 : for (auto & e : _boundary_data) 120 72 : e.second.centroid /= e.second.area; 121 : 122 : // fill vectors 123 24 : unsigned int j = 0; 124 96 : for (auto & e : _boundary_data) 125 : { 126 : // store away the sideset id first 127 72 : _sideset_ids[j] = e.first; 128 : 129 : // now work through the _vpp_entry_names vector 130 576 : for (unsigned int i = 0; i < _vpp_entry_names.size(); ++i) 131 504 : (*_meta_data[i])[j] = dataHelper(e.first, _vpp_entry_names[i]); 132 : 133 : // increment counter 134 72 : ++j; 135 : } 136 24 : } 137 : 138 : void 139 2 : SidesetInfoVectorPostprocessor::threadJoin(const UserObject & y) 140 : { 141 2 : const auto & vpp = static_cast<const SidesetInfoVectorPostprocessor &>(y); 142 : 143 8 : 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 6 : auto & vpp_bd = vpp._boundary_data.find(e.first)->second; 148 6 : auto & bd = e.second; 149 : 150 6 : bd.area += vpp_bd.area; 151 6 : bd.centroid += vpp_bd.centroid; 152 : 153 24 : for (unsigned int j = 0; j < 3; ++j) 154 : { 155 18 : if (vpp_bd.min(j) < bd.min(j)) 156 0 : bd.min(j) = vpp_bd.min(j); 157 : 158 18 : if (vpp_bd.max(j) > bd.max(j)) 159 4 : bd.max(j) = vpp_bd.max(j); 160 : } 161 : } 162 2 : } 163 : 164 : Real 165 504 : SidesetInfoVectorPostprocessor::dataHelper(BoundaryID bid, std::string mdat_tpe) const 166 : { 167 : mooseAssert(_boundary_data.find(bid) != _boundary_data.end(), 168 : "boundary id not found in _boundary_data."); 169 : 170 504 : auto & bd = _boundary_data.find(bid)->second; 171 : 172 504 : if (mdat_tpe == "centroid_x") 173 72 : return bd.centroid(0); 174 432 : else if (mdat_tpe == "centroid_y") 175 72 : return bd.centroid(1); 176 360 : else if (mdat_tpe == "centroid_z") 177 0 : return bd.centroid(2); 178 360 : else if (mdat_tpe == "min_x") 179 72 : return bd.min(0); 180 288 : else if (mdat_tpe == "min_y") 181 72 : return bd.min(1); 182 216 : else if (mdat_tpe == "min_z") 183 0 : return bd.min(2); 184 216 : else if (mdat_tpe == "max_x") 185 72 : return bd.max(0); 186 144 : else if (mdat_tpe == "max_y") 187 72 : return bd.max(1); 188 72 : else if (mdat_tpe == "max_z") 189 0 : return bd.max(2); 190 72 : else if (mdat_tpe == "area") 191 72 : return bd.area; 192 : else 193 0 : mooseError("meta_data_type not recognized. This should never happen."); 194 : }