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 5304 : copyReporterIntoPetscVector(const std::vector<std::vector<Real> *> reporterVectors, 22 : libMesh::PetscVector<Number> & x) 23 : { 24 : dof_id_type n = 0; 25 11086 : for (const auto & data : reporterVectors) 26 25687 : for (const auto & val : *data) 27 19905 : x.set(n++, val); 28 : 29 5304 : x.close(); 30 5304 : } 31 : 32 : void 33 15604 : copyPetscVectorIntoReporter(const libMesh::PetscVector<Number> & x, 34 : std::vector<std::vector<Real> *> reporterVectors) 35 : { 36 : dof_id_type j = 0; 37 32101 : for (auto & data : reporterVectors) 38 72742 : for (auto & val : *data) 39 56245 : val = x(j++); 40 15604 : } 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 : }