https://mooseframework.inl.gov
Loading...
Searching...
No Matches
OptUtils.C
Go to the documentation of this file.
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
17namespace OptUtils
18{
19
20void
21copyReporterIntoPetscVector(const std::vector<std::vector<Real> *> reporterVectors,
23{
24 dof_id_type n = 0;
25 for (const auto & data : reporterVectors)
26 for (const auto & val : *data)
27 x.set(n++, val);
28
29 x.close();
30}
31
32void
34 std::vector<std::vector<Real> *> reporterVectors)
35{
36 dof_id_type j = 0;
37 for (auto & data : reporterVectors)
38 for (auto & val : *data)
39 val = x(j++);
40}
41void
42copyReporterIntoPetscMatrix(const std::vector<std::vector<Real> *> reporterVectors,
44{
45 for (const auto i : index_range(reporterVectors))
46 for (const auto j : index_range(*reporterVectors[i]))
47 x.set(i, j, (*reporterVectors[i])[j]);
48
49 x.close();
50}
51
52void
54 std::vector<std::vector<Real> *> reporterVectors)
55{
56 for (const auto i : index_range(reporterVectors))
57 for (const auto j : index_range(*reporterVectors[i]))
58 (*reporterVectors[i])[j] = x(i, j);
59}
60}
const std::vector< double > x
void copyPetscMatrixIntoReporter(const libMesh::PetscMatrix< Number > &x, std::vector< std::vector< Real > * > reporterVectors)
Definition OptUtils.C:53
void copyReporterIntoPetscVector(const std::vector< std::vector< Real > * > reporterVectors, libMesh::PetscVector< Number > &x)
Definition OptUtils.C:21
void copyReporterIntoPetscMatrix(const std::vector< std::vector< Real > * > reporterVectors, libMesh::PetscMatrix< Number > &x)
Definition OptUtils.C:42
void copyPetscVectorIntoReporter(const libMesh::PetscVector< Number > &x, std::vector< std::vector< Real > * > reporterVectors)
Definition OptUtils.C:33