*/
const VectorReference &operator /= (const PetscScalar &s) const;
+ /**
+ * Return the real part of the value of the referenced element.
+ */
+ PetscReal real () const;
+
+ /**
+ * Return the imaginary part of the value of the referenced element.
+ *
+ * @note This operation is not defined for real numbers and an
+ * exception is thrown.
+ */
+ PetscReal imag () const;
+
/**
* Convert the reference to an actual value, i.e. return the value of
* the referenced element of the vector.
/**
* Return the scalar product of two vectors. The vectors must have the
* same size.
+ *
+ * For complex valued vector, this gives$\left(v^\ast,vec\right)$.
*/
PetscScalar operator * (const VectorBase &vec) const;
return *this;
}
- }
+ inline
+ PetscReal
+ VectorReference::real () const
+ {
+#ifndef PETSC_USE_COMPLEX
+ return static_cast<PetscScalar>(*this);
+#else
+ return PetscRealPart (static_cast<PetscScalar>(*this));
+#endif
+ }
+
+
+
+ inline
+ PetscReal
+ VectorReference::imag () const
+ {
+#ifndef PETSC_USE_COMPLEX
+ return PetscReal (0);
+#else
+ return PetscImaginaryPart (static_cast<PetscScalar>(*this));
+#endif
+ }
+
+ } // namespace internal
+
inline
bool
VectorBase::in_local_range (const size_type index) const
PetscScalar result;
- const int ierr = VecDot (vector, vec.vector, &result);
+ //For complex vectors, VecDot() computes
+ // val = (x,y) = y^H x,
+ //where y^H denotes the conjugate transpose of y.
+ //Note that this corresponds to the usual "mathematicians" complex inner product where the SECOND argument gets the complex conjugate.
+ const int ierr = VecDot (vec.vector, vector, &result);
AssertThrow (ierr == 0, ExcPETScError(ierr));
return result;