LCOV - code coverage report
Current view: top level - src/utils - OptUtils.C (source / functions) Hit Total Coverage
Test: idaholab/moose optimization: #31730 (e8b711) with base e0c998 Lines: 17 22 77.3 %
Date: 2025-10-29 16:52:42 Functions: 3 4 75.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 "OptUtils.h"
      11             : #include "libmesh/id_types.h"
      12             : #include "libmesh/petsc_vector.h"
      13             : #include "libmesh/petsc_matrix.h"
      14             : 
      15             : // static functions to copy Petsc vectors to and from vectors for a Reporter
      16             : 
      17             : namespace OptUtils
      18             : {
      19             : 
      20             : void
      21        6964 : copyReporterIntoPetscVector(const std::vector<std::vector<Real> *> reporterVectors,
      22             :                             libMesh::PetscVector<Number> & x)
      23             : {
      24             :   dof_id_type n = 0;
      25       14406 :   for (const auto & data : reporterVectors)
      26      309563 :     for (const auto & val : *data)
      27      302121 :       x.set(n++, val);
      28             : 
      29        6964 :   x.close();
      30        6964 : }
      31             : 
      32             : void
      33       18900 : copyPetscVectorIntoReporter(const libMesh::PetscVector<Number> & x,
      34             :                             std::vector<std::vector<Real> *> reporterVectors)
      35             : {
      36             :   dof_id_type j = 0;
      37       38693 :   for (auto & data : reporterVectors)
      38      634242 :     for (auto & val : *data)
      39      614449 :       val = x(j++);
      40       18900 : }
      41             : void
      42         504 : copyReporterIntoPetscMatrix(const std::vector<std::vector<Real> *> reporterVectors,
      43             :                             libMesh::PetscMatrix<Number> & x)
      44             : {
      45        1008 :   for (const auto i : index_range(reporterVectors))
      46        1512 :     for (const auto j : index_range(*reporterVectors[i]))
      47        1008 :       x.set(i, j, (*reporterVectors[i])[j]);
      48             : 
      49         504 :   x.close();
      50         504 : }
      51             : 
      52             : void
      53           0 : copyPetscMatrixIntoReporter(const libMesh::PetscMatrix<Number> & x,
      54             :                             std::vector<std::vector<Real> *> reporterVectors)
      55             : {
      56           0 :   for (const auto i : index_range(reporterVectors))
      57           0 :     for (const auto j : index_range(*reporterVectors[i]))
      58           0 :       (*reporterVectors[i])[j] = x(i, j);
      59           0 : }
      60             : }

Generated by: LCOV version 1.14