LCOV - code coverage report
Current view: top level - include/positions - Positions.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 5 8 62.5 %
Date: 2025-07-17 01:28:37 Functions: 4 8 50.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             : #pragma once
      11             : 
      12             : // Moose includes
      13             : #include "GeneralReporter.h"
      14             : #include "KDTree.h"
      15             : 
      16             : /**
      17             :  * Positions objects are under the hood Reporters.
      18             :  * But they are limited to vectors or multi-dimensional vectors of points.
      19             :  */
      20             : class Positions : public GeneralReporter
      21             : {
      22             : public:
      23             :   static InputParameters validParams();
      24             :   Positions(const InputParameters & parameters);
      25        1272 :   virtual ~Positions() = default;
      26             : 
      27             :   ///{
      28             :   /// Getters for the positions vector for the desired dimension
      29             :   /// 1D will be the only one guaranteed to succeed
      30             :   const std::vector<Point> & getPositions(bool initial) const;
      31             :   const std::vector<std::vector<Point>> & getPositionsVector2D() const;
      32             :   const std::vector<std::vector<std::vector<Point>>> & getPositionsVector3D() const;
      33             :   const std::vector<std::vector<std::vector<std::vector<Point>>>> & getPositionsVector4D() const;
      34             :   ///}
      35             : 
      36             :   /// Get the number of positions in the Positions object
      37      111226 :   unsigned int getNumPositions(bool initial = false) const
      38             :   {
      39             :     mooseAssert(initialized(initial), "Position should be initialized");
      40      111226 :     return (initial && _initial_positions) ? _initial_positions->size() : _positions.size();
      41             :   }
      42             : 
      43             :   /// Getter for a single position at a known index
      44             :   const Point & getPosition(unsigned int index, bool initial) const;
      45             : 
      46             :   /// Find the nearest Position for a given point
      47             :   const Point & getNearestPosition(const Point & target, bool initial) const;
      48             : 
      49             :   /// Find the nearest Position index for a given point
      50             :   unsigned int getNearestPositionIndex(const Point & target, bool initial) const;
      51             : 
      52             :   /// Find the minimum distance between positions
      53             :   Real getMinDistanceBetweenPositions() const;
      54             : 
      55             :   /// Report if the positions are co-planar or not
      56             :   bool arePositionsCoplanar() const;
      57             : 
      58             :   /// Whether the positions object has been initialized
      59             :   bool initialized(bool initial) const;
      60             : 
      61             : protected:
      62             :   /// In charge of computing / loading the positions.
      63             :   virtual void initialize() override = 0;
      64             : 
      65             :   /// By default, we wont execute often but "executing" will mean loading the positions
      66         334 :   virtual void execute() override { initialize(); }
      67             : 
      68             :   /// In charge of reduction across all ranks & sorting for consistent output
      69             :   virtual void finalize() override;
      70             : 
      71             :   /// By default, Positions will call initial setup on mesh changed
      72           0 :   virtual void meshChanged() override { initialSetup(); }
      73             : 
      74             :   /// By default, Positions will not be modified very regularly
      75        1241 :   virtual void timestepSetup() override {}
      76           0 :   virtual void residualSetup() override {}
      77           0 :   virtual void jacobianSetup() override {}
      78             : 
      79             :   /// Clear all positions vectors
      80             :   void clearPositions();
      81             : 
      82             :   /// Unrolls the multi-dimensional position vectors
      83             :   void unrollMultiDPositions();
      84             : 
      85             :   /// For initialization of the positions, another position reporter may be used
      86             :   const std::vector<Point> * const _initial_positions;
      87             : 
      88             :   /// For now, only the 1D vector will be shared across all ranks. All the others only exist
      89             :   /// locally.
      90             :   /// The 4 dimensions could be used for xyzt, but could also be axial/assembly/pin/ring
      91             :   /// 1D storage for all the positions
      92             :   std::vector<Point> & _positions;
      93             : 
      94             :   /// 2D storage for all the positions
      95             :   std::vector<std::vector<Point>> _positions_2d;
      96             : 
      97             :   /// 3D storage for all the positions
      98             :   std::vector<std::vector<std::vector<Point>>> _positions_3d;
      99             : 
     100             :   /// 4D storage for all the positions : space & time
     101             :   std::vector<std::vector<std::vector<std::vector<Point>>>> _positions_4d;
     102             : 
     103             :   /// KDTree to be able to find the nearest position to a point in a fast and scalable manner
     104             :   std::unique_ptr<KDTree> _initial_positions_kd_tree;
     105             :   std::unique_ptr<KDTree> _positions_kd_tree;
     106             : 
     107             :   /// Whether generation of positions is distributed or not (and therefore needs a broadcast)
     108             :   bool _need_broadcast;
     109             : 
     110             :   /// Whether positions should be sorted. Be careful with sorting! For example if initial positions
     111             :   /// are not sorted, then we switch to sorted positions, the mapping might be odd
     112             :   /// User may have also sorted their positions file, their input parameter etc
     113             :   const bool _need_sort;
     114             : 
     115             :   /// Whether the positions object has been initialized. This must be set by derived objects
     116             :   bool _initialized;
     117             : };

Generated by: LCOV version 1.14