LCOV - code coverage report
Current view: top level - src/positions - DistributedPositions.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 40 43 93.0 %
Date: 2025-08-08 20:01:16 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       14291 : DistributedPositions::validParams()
      16             : {
      17       14291 :   InputParameters params = Positions::validParams();
      18             : 
      19       14291 :   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       14291 :   params.set<bool>("auto_sort") = false;
      26             :   // If the base position is broadcast already we do not need to
      27       14291 :   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       42873 :   params.set<ExecFlagEnum>("execute_on") = {EXEC_LINEAR, EXEC_TIMESTEP_BEGIN};
      30             : 
      31       14291 :   params.addClassDescription(
      32             :       "Distribute positions, using translations, over one or more positions");
      33       14291 :   return params;
      34       14291 : }
      35             : 
      36          13 : DistributedPositions::DistributedPositions(const InputParameters & parameters)
      37          13 :   : Positions(parameters)
      38             : {
      39          13 :   const auto & base_names = getParam<std::vector<PositionsName>>("positions");
      40          39 :   for (const auto & base_name : base_names)
      41          26 :     if (_fe_problem.hasUserObject(base_name))
      42          26 :       _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          13 :   initialize();
      51             :   // Sort if needed (user-specified)
      52          13 :   finalize();
      53          13 : }
      54             : 
      55             : void
      56          37 : DistributedPositions::initialize()
      57             : {
      58          37 :   clearPositions();
      59          37 :   const bool initial = _fe_problem.getCurrentExecuteOnFlag() == EXEC_INITIAL;
      60             : 
      61             :   // Check that everything is initialized
      62         111 :   for (const auto * const pos_obj : _positions_objs)
      63          74 :     if (!pos_obj->initialized(initial))
      64           0 :       mooseError("Positions '", pos_obj->name(), "' is not initialized.");
      65             : 
      66             :   // Size new positions vector
      67          37 :   unsigned int n_positions = 1;
      68         111 :   for (const auto * const pos_obj : _positions_objs)
      69             :   {
      70          74 :     const auto n_pos_obj = pos_obj->getNumPositions(initial);
      71          74 :     if (n_pos_obj == 0)
      72           0 :       paramError("positions", "Positions " + pos_obj->name() + " has 0 positions.");
      73          74 :     n_positions *= pos_obj->getNumPositions(initial);
      74             :   }
      75          37 :   _positions.resize(n_positions);
      76             : 
      77             :   // Fill _positions by distributing using translations
      78          37 :   _positions[0] = Point(0, 0, 0);
      79          37 :   unsigned int current_index = 1;
      80         111 :   for (const auto pos_i : index_range(_positions_objs))
      81             :   {
      82          74 :     const auto * const current_positions = _positions_objs[_positions_objs.size() - 1 - pos_i];
      83         259 :     for (const auto i : make_range(current_index))
      84             :     {
      85         185 :       unsigned int j = 0;
      86         629 :       for (const auto & translation : current_positions->getPositions(initial))
      87         444 :         _positions[i + (j++) * current_index] += translation;
      88             :     }
      89          74 :     current_index *= current_positions->getNumPositions(initial);
      90             :   }
      91             : 
      92          37 :   _initialized = true;
      93          37 : }

Generated by: LCOV version 1.14