https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PetscVectorReader.h
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#pragma once
11
12#include "libmesh/petsc_vector.h"
13#include "libmesh/id_types.h"
14#include "libmesh/libmesh_common.h"
15#include "MooseError.h"
16
17using libMesh::Number;
21
28{
29public:
32
35
39
41 void restore();
42
44 PetscScalar operator()(const numeric_index_type i) const;
45
46private:
48 bool readable() const { return _raw_value != nullptr; }
49
52
54 const PetscScalar * _raw_value;
55};
56
57inline PetscScalar
58PetscVectorReader::operator()(const numeric_index_type i) const
59{
60 mooseAssert(readable(), "Not readable");
61 const numeric_index_type local_index = _vec.map_global_to_local_index(i);
62 return _raw_value[local_index];
63}
A class which helps with repeated reading from a petsc vector.
PetscScalar operator()(const numeric_index_type i) const
Access a value in the petsc vector.
void restore()
Restore the array, usually upon going out of scope.
const PetscScalar * _raw_value
The raw values in the vector.
bool readable() const
Check if this vector is readable.
~PetscVectorReader()
Destructor to make sure the vector is restored every time this goes out of scope.
PetscVector< Number > & _vec
Reference to the petsc vector whose values shall be read.
numeric_index_type map_global_to_local_index(const numeric_index_type i) const
dof_id_type numeric_index_type
Real Number