Skip to content
Snippets Groups Projects
Commit 5a9c4739 authored by Éric Béchet's avatar Éric Béchet
Browse files

No commit message

No commit message
parent 575011d9
No related branches found
No related tags found
No related merge requests found
...@@ -15,8 +15,32 @@ ...@@ -15,8 +15,32 @@
#include "linearSystemPETSc.hpp" #include "linearSystemPETSc.hpp"
template class linearSystemPETSc<double>; template class linearSystemPETSc<double>;
#ifdef PETSC_USE_COMPLEX #ifdef PETSC_USE_COMPLEX
template class linearSystemPETSc<std::complex<double> >; template class linearSystemPETSc<std::complex<double> >;
// this specialization will cast to a double (take the real part) if "val" is a double wheras Petsc is built in complex mode.
template <>
void linearSystemPETSc<double>::getFromRightHandSide(int row, double &val) const
{
PetscScalar *tmp;
_try(VecGetArray(_b, &tmp));
PetscScalar s = tmp[row];
_try(VecRestoreArray(_b, &tmp));
val = s.real();
}
// this specialization will cast to a double (take the real part) if "val" is a double wheras Petsc is built in complex mode.
template <>
void linearSystemPETSc<double>::getFromSolution(int row, double &val) const
{
PetscScalar *tmp;
_try(VecGetArray(_x, &tmp));
PetscScalar s = tmp[row];
_try(VecRestoreArray(_x, &tmp));
val = s.real();
}
#endif #endif
template<> template<>
......
...@@ -266,20 +266,16 @@ void linearSystemPETSc<scalar>::addToRightHandSide(int row, const scalar &val) ...@@ -266,20 +266,16 @@ void linearSystemPETSc<scalar>::addToRightHandSide(int row, const scalar &val)
PetscScalar s = val; PetscScalar s = val;
_try(VecSetValues(_b, 1, &i, &s, ADD_VALUES)); _try(VecSetValues(_b, 1, &i, &s, ADD_VALUES));
} }
#if defined(PETSC_USE_COMPLEX)
// this specialization will cast to a double (take the real part) if "val" is a double wheras Petsc is built in complex mode.
template <>
void linearSystemPETSc<double>::getFromRightHandSide(int row, double &val) const;
#endif
template <class scalar> template <class scalar>
void linearSystemPETSc<scalar>::getFromRightHandSide(int row, scalar &val) const void linearSystemPETSc<scalar>::getFromRightHandSide(int row, scalar &val) const
{ {
#if defined(PETSC_USE_COMPLEX)
PetscScalar *tmp;
_try(VecGetArray(_b, &tmp));
PetscScalar s = tmp[row];
_try(VecRestoreArray(_b, &tmp));
// FIXME specialize this routine
val = s.real();
#else
_try(VecGetValues(_b, 1, &row, &val)); _try(VecGetValues(_b, 1, &row, &val));
#endif
} }
template <class scalar> template <class scalar>
...@@ -310,19 +306,16 @@ void linearSystemPETSc<scalar>::addToSolution(int row, const scalar &val) ...@@ -310,19 +306,16 @@ void linearSystemPETSc<scalar>::addToSolution(int row, const scalar &val)
PetscScalar s = val; PetscScalar s = val;
_try(VecSetValues(_x, 1, &i, &s, ADD_VALUES)); _try(VecSetValues(_x, 1, &i, &s, ADD_VALUES));
} }
#if defined(PETSC_USE_COMPLEX)
// this specialization will cast to a double (take the real part) if "val" is a double wheras Petsc is built in complex mode.
template <>
void linearSystemPETSc<double>::getFromSolution(int row, double &val) const;
#endif
template <class scalar> template <class scalar>
void linearSystemPETSc<scalar>::getFromSolution(int row, scalar &val) const void linearSystemPETSc<scalar>::getFromSolution(int row, scalar &val) const
{ {
#if defined(PETSC_USE_COMPLEX)
PetscScalar *tmp;
_try(VecGetArray(_x, &tmp));
PetscScalar s = tmp[row];
_try(VecRestoreArray(_x, &tmp));
val = s.real();
#else
_try(VecGetValues(_x, 1, &row, &val)); _try(VecGetValues(_x, 1, &row, &val));
#endif
} }
template <class scalar> template <class scalar>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment