LCOV - code coverage report
Current view: top level - include/vectorpostprocessors - SamplerBase.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 1 1 100.0 %
Date: 2025-08-08 20:01:16 Functions: 1 2 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 "MooseTypes.h"
      14             : 
      15             : // Forward Declarations
      16             : class InputParameters;
      17             : class VectorPostprocessor;
      18             : class TransientBase;
      19             : 
      20             : namespace libMesh
      21             : {
      22             : class Point;
      23             : 
      24             : namespace Parallel
      25             : {
      26             : class Communicator;
      27             : }
      28             : }
      29             : 
      30             : template <typename T>
      31             : InputParameters validParams();
      32             : 
      33             : /**
      34             :  * Base class for VectorPostprocessors that need to do "sampling" of
      35             :  * values in the domain.
      36             :  */
      37             : class SamplerBase
      38             : {
      39             : public:
      40             :   static InputParameters validParams();
      41             : 
      42             :   /**
      43             :    * @param parameters The parameters for the object
      44             :    * @param vpp A pointer to the child object
      45             :    * @param comm The communicator of the child
      46             :    */
      47             :   SamplerBase(const InputParameters & parameters,
      48             :               VectorPostprocessor * vpp,
      49             :               const libMesh::Parallel::Communicator & comm);
      50        1738 :   virtual ~SamplerBase() = default;
      51             : 
      52             : protected:
      53             :   /**
      54             :    * You MUST call this in the constructor of the child class and pass down the name
      55             :    * of the variables.
      56             :    *
      57             :    * @param variable_names The names of the variables.  Note: The order of the variables sets the
      58             :    * order of the values for addSample()
      59             :    */
      60             :   void setupVariables(const std::vector<std::string> & variable_names);
      61             : 
      62             :   /**
      63             :    *  Checks whether the passed variable pointer corresponds to a regular single-valued field
      64             :    * variable
      65             :    * @param var_param_name name of the variable parameter in which the variables were passed
      66             :    * @param var_ptr pointer to the field variable
      67             :    */
      68             :   void checkForStandardFieldVariableType(const MooseVariableFieldBase * const var_ptr,
      69             :                                          const std::string & var_param_name = "variable") const;
      70             : 
      71             :   /**
      72             :    * Call this with the value of every variable at each point you want to sample at.
      73             :    * @param p The point where you took the sample
      74             :    * @param id This can either be an actual ID or a distance or anything else you want
      75             :    * @param values The value of each variable
      76             :    */
      77             :   virtual void addSample(const Point & p, const Real & id, const std::vector<Real> & values);
      78             : 
      79             :   /**
      80             :    * Initialize the datastructures.
      81             :    *
      82             :    * YOU MUST CALL THIS DURING initialize() in the child class!
      83             :    */
      84             :   virtual void initialize();
      85             : 
      86             :   /**
      87             :    * Finalize the values.
      88             :    *
      89             :    * YOU MUST CALL THIS DURING finalize() in the child class!
      90             :    */
      91             :   virtual void finalize();
      92             : 
      93             :   /**
      94             :    * Join the values.
      95             :    *
      96             :    * YOU MUST CALL THIS DURING threadJoin() in the child class!
      97             :    *
      98             :    * @param y You must cast the UserObject to your child class type first then you can pass it in
      99             :    * here.
     100             :    */
     101             :   virtual void threadJoin(const SamplerBase & y);
     102             : 
     103             :   /// The child params
     104             :   const InputParameters & _sampler_params;
     105             : 
     106             :   /// The child VectorPostprocessor
     107             :   VectorPostprocessor * _vpp;
     108             : 
     109             :   /// The communicator of the child
     110             :   const libMesh::Parallel::Communicator & _comm;
     111             : 
     112             :   /// Transient executioner used to determine if the last solve converged
     113             :   const TransientBase * const _sampler_transient;
     114             : 
     115             :   /// The variable names
     116             :   std::vector<std::string> _variable_names;
     117             : 
     118             :   /// What to sort by
     119             :   const unsigned int _sort_by;
     120             : 
     121             :   /// x coordinate of the points
     122             :   VectorPostprocessorValue & _x;
     123             :   /// y coordinate of the points
     124             :   VectorPostprocessorValue & _y;
     125             :   /// x coordinate of the points
     126             :   VectorPostprocessorValue & _z;
     127             : 
     128             :   /// The node ID of each point
     129             :   VectorPostprocessorValue & _id;
     130             : 
     131             :   std::vector<VectorPostprocessorValue *> _values;
     132             : 
     133             : private:
     134             :   /// The number of samples added in the last execution
     135             :   std::size_t _curr_num_samples = 0;
     136             :   /// The indices of the samples in the last execution
     137             :   std::set<std::size_t, std::greater<std::size_t>> _curr_indices;
     138             :   /// The full size of the vector since the last execution
     139             :   std::size_t _curr_total_samples = 0;
     140             : };

Generated by: LCOV version 1.14