LCOV - code coverage report
Current view: top level - src/positions - DistributedPositions.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 40 43 93.0 %
Date: 2025-07-17 01:28:37 Functions: 3 3 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 "DistributedPositions.h"
      11             : 
      12             : registerMooseObject("MooseApp", DistributedPositions);
      13             : 
      14             : InputParameters
      15       14289 : DistributedPositions::validParams()
      16             : {
      17       14289 :   InputParameters params = Positions::validParams();
      18             : 
      19       14289 :   params.addRequiredParam<std::vector<PositionsName>>(
      20             :       "positions",
      21             :       "Positions object. The last Positions is distributed over all the Positions prior in the "
      22             :       "vector parameter.");
      23             : 
      24             :   // Use position ordering from the distribution
      25       14289 :   params.set<bool>("auto_sort") = false;
      26             :   // If the base position is broadcast already we do not need to
      27       14289 :   params.set<bool>("auto_broadcast") = false;
      28             :   // Keep as up-to-date as possible given that the incoming position to distribute could be changing
      29       42867 :   params.set<ExecFlagEnum>("execute_on") = {EXEC_LINEAR, EXEC_TIMESTEP_BEGIN};
      30             : 
      31       14289 :   params.addClassDescription(
      32             :       "Distribute positions, using translations, over one or more positions");
      33       14289 :   return params;
      34       14289 : }
      35             : 
      36          12 : DistributedPositions::DistributedPositions(const InputParameters & parameters)
      37          12 :   : Positions(parameters)
      38             : {
      39          12 :   const auto & base_names = getParam<std::vector<PositionsName>>("positions");
      40          36 :   for (const auto & base_name : base_names)
      41          24 :     if (_fe_problem.hasUserObject(base_name))
      42          24 :       _positions_objs.push_back(&_fe_problem.getPositionsObject(base_name));
      43             :     else
      44           0 :       mooseError("Positions ",
      45             :                  base_name,
      46             :                  " has not been created yet. If it exists, re-order Positions in the input "
      47             :                  "file or implement automated construction ordering");
      48             : 
      49             :   // Obtain the positions from the nested positions objects, then transform them
      50          12 :   initialize();
      51             :   // Sort if needed (user-specified)
      52          12 :   finalize();
      53          12 : }
      54             : 
      55             : void
      56          34 : DistributedPositions::initialize()
      57             : {
      58          34 :   clearPositions();
      59          34 :   const bool initial = _fe_problem.getCurrentExecuteOnFlag() == EXEC_INITIAL;
      60             : 
      61             :   // Check that everything is initialized
      62         102 :   for (const auto * const pos_obj : _positions_objs)
      63          68 :     if (!pos_obj->initialized(initial))
      64           0 :       mooseError("Positions '", pos_obj->name(), "' is not initialized.");
      65             : 
      66             :   // Size new positions vector
      67          34 :   unsigned int n_positions = 1;
      68         102 :   for (const auto * const pos_obj : _positions_objs)
      69             :   {
      70          68 :     const auto n_pos_obj = pos_obj->getNumPositions(initial);
      71          68 :     if (n_pos_obj == 0)
      72           0 :       paramError("positions", "Positions " + pos_obj->name() + " has 0 positions.");
      73          68 :     n_positions *= pos_obj->getNumPositions(initial);
      74             :   }
      75          34 :   _positions.resize(n_positions);
      76             : 
      77             :   // Fill _positions by distributing using translations
      78          34 :   _positions[0] = Point(0, 0, 0);
      79          34 :   unsigned int current_index = 1;
      80         102 :   for (const auto pos_i : index_range(_positions_objs))
      81             :   {
      82          68 :     const auto * const current_positions = _positions_objs[_positions_objs.size() - 1 - pos_i];
      83         238 :     for (const auto i : make_range(current_index))
      84             :     {
      85         170 :       unsigned int j = 0;
      86         578 :       for (const auto & translation : current_positions->getPositions(initial))
      87         408 :         _positions[i + (j++) * current_index] += translation;
      88             :     }
      89          68 :     current_index *= current_positions->getNumPositions(initial);
      90             :   }
      91             : 
      92          34 :   _initialized = true;
      93          34 : }

Generated by: LCOV version 1.14