LCOV - code coverage report
Current view: top level - src/vectorpostprocessors - SidesetInfoVectorPostprocessor.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 98 105 93.3 %
Date: 2025-07-17 01:28:37 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          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       14315 : SidesetInfoVectorPostprocessor::validParams()
      19             : {
      20       14315 :   InputParameters params = SideVectorPostprocessor::validParams();
      21       14315 :   MultiMooseEnum meta_data_types("centroid=0 min=1 max=2 area=3");
      22       14315 :   params.addParam<MultiMooseEnum>(
      23             :       "meta_data_types", meta_data_types, "Data types that are obtained and written to file.");
      24       14315 :   params.addClassDescription("This VectorPostprocessor collects meta data for provided sidesets.");
      25       28630 :   return params;
      26       14315 : }
      27             : 
      28          26 : SidesetInfoVectorPostprocessor::SidesetInfoVectorPostprocessor(const InputParameters & parameters)
      29             :   : SideVectorPostprocessor(parameters),
      30          26 :     _meta_data_types(getParam<MultiMooseEnum>("meta_data_types")),
      31          52 :     _sideset_ids(declareVector("Boundary IDs"))
      32             : {
      33             :   // this sets up the _vpp_entry_names vector
      34         130 :   for (unsigned int j = 0; j < _meta_data_types.size(); ++j)
      35             :   {
      36         156 :     if (_meta_data_types[j] == "centroid" || _meta_data_types[j] == "min" ||
      37          52 :         _meta_data_types[j] == "max")
      38             :     {
      39         234 :       for (unsigned int d = 0; d < _mesh.dimension(); ++d)
      40             :       {
      41         156 :         std::stringstream ss;
      42         156 :         ss << _meta_data_types[j] << "_";
      43         156 :         if (d == 0)
      44          78 :           ss << "x";
      45          78 :         else if (d == 1)
      46          78 :           ss << "y";
      47           0 :         else if (d == 2)
      48           0 :           ss << "z";
      49         156 :         _vpp_entry_names.push_back(ss.str());
      50         156 :       }
      51             :     }
      52             :     else
      53          26 :       _vpp_entry_names.push_back(_meta_data_types[j]);
      54             :   }
      55             : 
      56             :   // now we can initialize the _meta_data vector
      57          26 :   _meta_data.resize(_vpp_entry_names.size());
      58         208 :   for (unsigned int j = 0; j < _vpp_entry_names.size(); ++j)
      59         182 :     _meta_data[j] = &declareVector(_vpp_entry_names[j]);
      60          26 : }
      61             : 
      62             : void
      63          24 : SidesetInfoVectorPostprocessor::initialize()
      64             : {
      65             :   // Clear existing data
      66          24 :   _sideset_ids.clear();
      67         192 :   for (unsigned int j = 0; j < _vpp_entry_names.size(); ++j)
      68         168 :     _meta_data[j]->clear();
      69             : 
      70          96 :   for (auto & e : boundaryIDs())
      71          72 :     _boundary_data[e] = BoundaryData();
      72             : 
      73             :   // resize containers for possibly new number of boundaries
      74          24 :   _sideset_ids.resize(numBoundaryIDs());
      75         192 :   for (unsigned int j = 0; j < _vpp_entry_names.size(); ++j)
      76         168 :     _meta_data[j]->resize(numBoundaryIDs());
      77          24 : }
      78             : 
      79             : void
      80         288 : 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         288 :   auto & bd = _boundary_data.find(_current_boundary_id)->second;
      86         288 :   bd.area += _current_side_volume;
      87         288 :   bd.centroid += _current_side_elem->vertex_average() * _current_side_volume;
      88             : 
      89         288 :   BoundingBox box = _current_side_elem->loose_bounding_box();
      90         288 :   Point lmin = box.min();
      91         288 :   Point lmax = box.max();
      92             : 
      93        1152 :   for (unsigned int j = 0; j < 3; ++j)
      94             :   {
      95         864 :     if (lmin(j) < bd.min(j))
      96         174 :       bd.min(j) = lmin(j);
      97             : 
      98         864 :     if (lmax(j) > bd.max(j))
      99         404 :       bd.max(j) = lmax(j);
     100             :   }
     101         288 : }
     102             : 
     103             : void
     104          22 : SidesetInfoVectorPostprocessor::finalize()
     105             : {
     106          88 :   for (auto & e : _boundary_data)
     107             :   {
     108          66 :     auto & bd = e.second;
     109          66 :     gatherSum(bd.area);
     110         264 :     for (unsigned int j = 0; j < 3; ++j)
     111             :     {
     112         198 :       gatherMin(bd.min(j));
     113         198 :       gatherMax(bd.max(j));
     114         198 :       gatherSum(bd.centroid(j));
     115             :     }
     116             :   }
     117             : 
     118             :   // centroid needs to be divided by area
     119          88 :   for (auto & e : _boundary_data)
     120          66 :     e.second.centroid /= e.second.area;
     121             : 
     122             :   // fill vectors
     123          22 :   unsigned int j = 0;
     124          88 :   for (auto & e : _boundary_data)
     125             :   {
     126             :     // store away the sideset id first
     127          66 :     _sideset_ids[j] = e.first;
     128             : 
     129             :     // now work through the _vpp_entry_names vector
     130         528 :     for (unsigned int i = 0; i < _vpp_entry_names.size(); ++i)
     131         462 :       (*_meta_data[i])[j] = dataHelper(e.first, _vpp_entry_names[i]);
     132             : 
     133             :     // increment counter
     134          66 :     ++j;
     135             :   }
     136          22 : }
     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         462 : 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         462 :   auto & bd = _boundary_data.find(bid)->second;
     171             : 
     172         462 :   if (mdat_tpe == "centroid_x")
     173          66 :     return bd.centroid(0);
     174         396 :   else if (mdat_tpe == "centroid_y")
     175          66 :     return bd.centroid(1);
     176         330 :   else if (mdat_tpe == "centroid_z")
     177           0 :     return bd.centroid(2);
     178         330 :   else if (mdat_tpe == "min_x")
     179          66 :     return bd.min(0);
     180         264 :   else if (mdat_tpe == "min_y")
     181          66 :     return bd.min(1);
     182         198 :   else if (mdat_tpe == "min_z")
     183           0 :     return bd.min(2);
     184         198 :   else if (mdat_tpe == "max_x")
     185          66 :     return bd.max(0);
     186         132 :   else if (mdat_tpe == "max_y")
     187          66 :     return bd.max(1);
     188          66 :   else if (mdat_tpe == "max_z")
     189           0 :     return bd.max(2);
     190          66 :   else if (mdat_tpe == "area")
     191          66 :     return bd.area;
     192             :   else
     193           0 :     mooseError("meta_data_type not recognized. This should never happen.");
     194             : }

Generated by: LCOV version 1.14