LCOV - code coverage report
Current view: top level - src/trainers - NearestPointTrainer.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: #32971 (54bef8) with base c6cf66 Lines: 36 37 97.3 %
Date: 2026-05-29 20:40:35 Functions: 5 5 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 "NearestPointTrainer.h"
      11             : #include "Sampler.h"
      12             : 
      13             : registerMooseObject("StochasticToolsApp", NearestPointTrainer);
      14             : 
      15             : InputParameters
      16         142 : NearestPointTrainer::validParams()
      17             : {
      18         142 :   InputParameters params = SurrogateTrainer::validParams();
      19         142 :   params.addClassDescription("Loops over and saves sample values for [NearestPointSurrogate.md].");
      20             : 
      21         142 :   return params;
      22           0 : }
      23             : 
      24          71 : NearestPointTrainer::NearestPointTrainer(const InputParameters & parameters)
      25             :   : SurrogateTrainer(parameters),
      26          71 :     _sample_points(declareModelData<std::vector<std::vector<Real>>>("_sample_points")),
      27         142 :     _sample_results(declareModelData<std::vector<std::vector<Real>>>("_sample_results")),
      28          71 :     _predictor_row(getPredictorData())
      29             : {
      30          71 :   _sample_points.resize(_n_dims);
      31          71 :   _sample_results.resize(1);
      32          71 : }
      33             : 
      34             : void
      35         161 : NearestPointTrainer::preTrain()
      36             : {
      37         742 :   for (auto & it : _sample_points)
      38             :   {
      39         581 :     it.clear();
      40         581 :     it.reserve(getLocalSampleSize());
      41             :   }
      42             : 
      43         322 :   for (auto & it : _sample_results)
      44             :   {
      45         161 :     it.clear();
      46         161 :     it.reserve(getLocalSampleSize());
      47             :   }
      48         161 : }
      49             : 
      50             : void
      51       11390 : NearestPointTrainer::train()
      52             : {
      53       11390 :   if (_rvecval && (_sample_results.size() != _rvecval->size()))
      54           7 :     _sample_results.resize(_rvecval->size());
      55             : 
      56             :   // Get predictors from reporter values
      57       46620 :   for (auto d : make_range(_n_dims))
      58       35230 :     _sample_points[d].push_back(_predictor_row[d]);
      59             : 
      60             :   // Get responses
      61       11390 :   if (_rval)
      62       11340 :     _sample_results[0].push_back(*_rval);
      63          50 :   else if (_rvecval)
      64         550 :     for (auto r : make_range(_rvecval->size()))
      65         500 :       _sample_results[r].push_back((*_rvecval)[r]);
      66       11390 : }
      67             : 
      68             : void
      69         161 : NearestPointTrainer::postTrain()
      70             : {
      71         742 :   for (auto & it : _sample_points)
      72         581 :     _communicator.allgather(it);
      73             : 
      74         385 :   for (auto & it : _sample_results)
      75         224 :     _communicator.allgather(it);
      76         161 : }

Generated by: LCOV version 1.14