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 "MultiAppPositions.h" 11 : #include "FEProblemBase.h" 12 : #include "DisplacedProblem.h" 13 : 14 : registerMooseObject("MooseApp", MultiAppPositions); 15 : 16 : InputParameters 17 14851 : MultiAppPositions::validParams() 18 : { 19 14851 : InputParameters params = Positions::validParams(); 20 14851 : params.addRequiredParam<std::vector<MultiAppName>>( 21 : "multiapps", "Name(s) of the multiapps providing the positions"); 22 44553 : params.addParam<bool>("use_apps_centroid", 23 29702 : false, 24 : "Whether to use the mesh centroid offset by the app position rather than " 25 : "just the position of each child app"); 26 : 27 : // Execute after multiapps have been created 28 14851 : params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL; 29 : // Positions of subapps should stay ordered the same as the subapps 30 14851 : params.set<bool>("auto_sort") = false; 31 : // Subapp positions are known for all processes already 32 14851 : params.set<bool>("auto_broadcast") = false; 33 : 34 14851 : params.addClassDescription( 35 : "Obtain positions from MultiApps. This may only be used to set the positions of those same " 36 : "multiapps if an 'initial_positions' parameter is used."); 37 14851 : return params; 38 0 : } 39 : 40 293 : MultiAppPositions::MultiAppPositions(const InputParameters & parameters) 41 293 : : Positions(parameters), _use_apps_centroid(getParam<bool>("use_apps_centroid")) 42 : { 43 : // Centroids cannot be computed for non-local apps 44 293 : if (_use_apps_centroid) 45 12 : _need_broadcast = true; 46 293 : } 47 : 48 : void 49 708 : MultiAppPositions::initialize() 50 : { 51 708 : clearPositions(); 52 : 53 708 : const auto & multiapps = getParam<std::vector<MultiAppName>>("multiapps"); 54 708 : _positions_2d.resize(multiapps.size()); 55 : 56 1548 : for (const auto m_it : index_range(multiapps)) 57 : { 58 844 : const std::string & multiapp_name = multiapps[m_it]; 59 844 : const auto & multiapp = _fe_problem.getMultiApp(multiapp_name); 60 : 61 3000 : for (const auto & i_global : make_range(multiapp->numGlobalApps())) 62 : { 63 2160 : const auto p = multiapp->position(i_global); 64 2156 : if (!_use_apps_centroid) 65 : { 66 2020 : _positions.push_back(p); 67 2020 : _positions_2d[m_it].push_back(p); 68 : } 69 : // Get the centroid of each subapp mesh 70 : else 71 : { 72 : // Cant compute centroid if does not own the mesh 73 136 : if (!multiapp->hasLocalApp(i_global)) 74 18 : continue; 75 118 : auto & fe_problem_base = multiapp->appProblemBase(i_global); 76 236 : const MeshBase & mesh = (getParam<bool>("use_displaced_mesh") && 77 118 : fe_problem_base.getDisplacedProblem().get() != NULL) 78 118 : ? fe_problem_base.getDisplacedProblem()->mesh().getMesh() 79 236 : : fe_problem_base.mesh().getMesh(); 80 118 : const Point centroid = MooseMeshUtils::meshCentroidCalculator(mesh); 81 : 82 : // There's a broadcast after, no need to add on every rank 83 118 : if (multiapp->isFirstLocalRank()) 84 : { 85 100 : _positions.push_back(p + centroid); 86 100 : _positions_2d[m_it].push_back(p + centroid); 87 : } 88 : } 89 : } 90 840 : } 91 704 : _initialized = true; 92 704 : }