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

Generated by: LCOV version 1.14