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 "ElementCentroidPositions.h" 11 : 12 : registerMooseObject("MooseApp", ElementCentroidPositions); 13 : 14 : InputParameters 15 14537 : ElementCentroidPositions::validParams() 16 : { 17 14537 : InputParameters params = Positions::validParams(); 18 14537 : params.addClassDescription("Positions of element centroids."); 19 14537 : params += BlockRestrictable::validParams(); 20 : 21 : // Element centroids could be sorted by XYZ or by id. Default to not sorting 22 14537 : params.set<bool>("auto_sort") = false; 23 : // Gathered locally, should be broadcast on every process 24 14537 : params.set<bool>("auto_broadcast") = true; 25 : 26 14537 : return params; 27 0 : } 28 : 29 136 : ElementCentroidPositions::ElementCentroidPositions(const InputParameters & parameters) 30 136 : : Positions(parameters), BlockRestrictable(this), _mesh(_fe_problem.mesh()) 31 : { 32 : // Mesh is ready at construction 33 136 : initialize(); 34 : // Trigger synchronization as the initialization is distributed 35 136 : finalize(); 36 136 : } 37 : 38 : void 39 136 : ElementCentroidPositions::initialize() 40 : { 41 136 : clearPositions(); 42 : 43 : // By default, initialize should be called on meshChanged() 44 : // Gathering of positions is local, reporter system makes sure to make it global 45 136 : if (blockRestricted()) 46 : { 47 12 : _positions_2d.resize(numBlocks()); 48 12 : unsigned int b_index = 0; 49 24 : for (const auto & sub_id : blockIDs()) 50 : { 51 300 : for (const auto & elem : _mesh.getMesh().active_local_subdomain_elements_ptr_range(sub_id)) 52 : { 53 144 : auto centroid = elem->true_centroid(); 54 144 : _positions.emplace_back(centroid); 55 144 : _positions_2d[b_index].emplace_back(centroid); 56 12 : } 57 12 : b_index += 1; 58 : } 59 : } 60 : else 61 : { 62 124 : _positions.resize(_mesh.getMesh().n_active_local_elem()); 63 124 : unsigned int i = 0; 64 1130 : for (const auto & elem : _mesh.getMesh().active_local_element_ptr_range()) 65 1130 : _positions[i++] = elem->true_centroid(); 66 : } 67 136 : _initialized = true; 68 136 : }