LCOV - code coverage report
Current view: top level - include/transfers - MultiAppGeneralFieldNearestLocationTransfer.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 1 1 100.0 %
Date: 2025-07-17 01:28:37 Functions: 1 1 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             : #pragma once
      11             : 
      12             : #include "MultiAppGeneralFieldTransfer.h"
      13             : #include "KDTree.h"
      14             : #include "SolutionInvalidInterface.h"
      15             : 
      16             : /**
      17             :  * Performs a geometric interpolation based on the values at the nearest nodes to a target location
      18             :  * in the origin mesh.
      19             :  */
      20             : class MultiAppGeneralFieldNearestLocationTransfer : public MultiAppGeneralFieldTransfer,
      21             :                                                     public SolutionInvalidInterface
      22             : 
      23             : {
      24             : public:
      25             :   static InputParameters validParams();
      26             : 
      27             :   MultiAppGeneralFieldNearestLocationTransfer(const InputParameters & parameters);
      28             : 
      29             :   void initialSetup() override;
      30             : 
      31             : protected:
      32             :   virtual void prepareEvaluationOfInterpValues(const unsigned int var_index) override;
      33             : 
      34             :   virtual void
      35             :   evaluateInterpValues(const std::vector<std::pair<Point, unsigned int>> & incoming_points,
      36             :                        std::vector<std::pair<Real, Real>> & outgoing_vals) override;
      37             : 
      38             :   using MultiAppGeneralFieldTransfer::inBlocks;
      39             :   bool inBlocks(const std::set<SubdomainID> & blocks,
      40             :                 const MooseMesh & mesh,
      41             :                 const Elem * elem) const override;
      42             : 
      43             : private:
      44         322 :   bool usesMooseAppCoordTransform() const override { return true; }
      45             :   /*
      46             :    * Build KD-Trees for each local app
      47             :    * @param var_index the index of the variable being transferred
      48             :    * @details fills _local_kdtrees, _local_points and _local_values
      49             :    *          Indexing is: local apps (outer-indexing) OR positions (if using nearest_positions),
      50             :    *          local nodes (inner-indexing)
      51             :    */
      52             :   void buildKDTrees(const unsigned int var_index);
      53             : 
      54             :   /*
      55             :    * Evaluate interpolation values for incoming points
      56             :    * @param incoming_points all the points at which we need values
      57             :    * @param outgoing_vals vector containing the values and distances from point to nearest node
      58             :    */
      59             :   void evaluateInterpValuesNearestNode(
      60             :       const std::vector<std::pair<Point, unsigned int>> & incoming_points,
      61             :       std::vector<std::pair<Real, Real>> & outgoing_vals);
      62             : 
      63             :   /// Pre-compute the number of sources
      64             :   /// Number of KDTrees used to hold the locations and variable value data
      65             :   void computeNumSources();
      66             : 
      67             :   /// Get the index of the app in the loop over the trees and the apps contributing data to each tree
      68             :   unsigned int getAppIndex(unsigned int kdtree_index, unsigned int app_index) const;
      69             : 
      70             :   /// Number of applications which contributed nearest-locations to each KD-tree
      71             :   unsigned int getNumAppsPerTree() const;
      72             : 
      73             :   /// Number of divisions (nearest-positions or source mesh divisions) used when building KD-Trees
      74             :   unsigned int getNumDivisions() const;
      75             : 
      76             :   /// Transform a point towards the local frame
      77             :   Point getPointInLocalSourceFrame(unsigned int i_from, const Point & pt) const;
      78             : 
      79             :   /**
      80             :    * @brief Examine all spatial restrictions that could preclude this source from being
      81             :    *        a valid source for this point
      82             :    * @param pt point of interest
      83             :    * @param valid_mesh_div if using source mesh divisions in a 'matching' mode, the point can only
      84             :    * be used if coming from the relevant match
      85             :    * @param i_from index of the source (KDTree+values) of interest
      86             :    */
      87             :   bool checkRestrictionsForSource(const Point & pt,
      88             :                                   const unsigned int valid_mesh_div,
      89             :                                   const unsigned int i_from) const;
      90             : 
      91             :   /// KD-Trees for all the local source apps
      92             :   std::vector<std::shared_ptr<KDTree>> _local_kdtrees;
      93             : 
      94             :   /// KD-Trees for nodes nearest to a given position on each local source app
      95             :   std::vector<std::vector<std::shared_ptr<KDTree>>> _local_positions_kdtrees;
      96             : 
      97             :   /// All the nodes that meet the spatial restrictions in all the local source apps
      98             :   std::vector<std::vector<Point>> _local_points;
      99             : 
     100             :   /// Values of the variable being transferred at all the points in _local_points
     101             :   std::vector<std::vector<Real>> _local_values;
     102             : 
     103             :   /// Number of points to consider
     104             :   unsigned int _num_nearest_points;
     105             : 
     106             :   /// Whether to group data when creating the nearest-point regions
     107             :   const bool _group_subapps;
     108             : 
     109             :   /// Whether the source of the values is at nodes (true) or centroids (false) for each variable
     110             :   std::vector<bool> _source_is_nodes;
     111             : 
     112             :   /// Whether we can just use the local zero-indexed dof to get the value from the solution
     113             :   std::vector<bool> _use_zero_dof_for_value;
     114             : 
     115             :   /// Number of KD-Trees to create
     116             :   unsigned int _num_sources;
     117             : };

Generated by: LCOV version 1.14