GEOS
PetscUtils.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_LINEARALGEBRA_INTERFACES_PETSCUTILS_HPP
21 #define GEOS_LINEARALGEBRA_INTERFACES_PETSCUTILS_HPP
22 
23 #include "common/DataTypes.hpp"
24 
25 #include <petscsys.h>
26 
27 namespace geos
28 {
29 
30 namespace petsc
31 {
32 
33 // Check matching requirements on index/value types between GEOSX and PETSc
34 
35 static_assert( sizeof( PetscInt ) == sizeof( geos::globalIndex ),
36  "PetscInt and geos::globalIndex must have the same size" );
37 
38 static_assert( std::is_signed< PetscInt >::value == std::is_signed< geos::globalIndex >::value,
39  "PetscInt and geoex::globalIndex must both be signed or unsigned" );
40 
41 static_assert( std::is_same< PetscScalar, geos::real64 >::value,
42  "PetscScalar and geos::real64 must be the same type" );
43 
49 inline PetscInt * toPetscInt( globalIndex * const index )
50 {
51  return reinterpret_cast< PetscInt * >(index);
52 }
53 
59 inline PetscInt const * toPetscInt( globalIndex const * const index )
60 {
61  return reinterpret_cast< PetscInt const * >(index);
62 }
63 
64 } // namespace petsc
65 
66 } // namespace geos
67 
68 #endif //GEOS_LINEARALGEBRA_INTERFACES_PETSCUTILS_HPP
PetscInt * toPetscInt(globalIndex *const index)
Converts a non-const array from GEOSX globalIndex type to PetscInt.
Definition: PetscUtils.hpp:49
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:88