Thyra
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
core
test
nonlinear
models
Thyra_DiagonalScalarProd_def.hpp
1
// @HEADER
2
// *****************************************************************************
3
// Thyra: Interfaces and Support for Abstract Numerical Algorithms
4
//
5
// Copyright 2004 NTESS and the Thyra contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
10
#ifndef THYRA_DIAGONAL_SCALAR_PROD_DEF_HPP
11
#define THYRA_DIAGONAL_SCALAR_PROD_DEF_HPP
12
13
14
#include "Thyra_DiagonalScalarProd_decl.hpp"
15
#include "Thyra_DetachedSpmdVectorView.hpp"
16
#include "Thyra_SpmdVectorSpaceBase.hpp"
17
#include "Thyra_AssertOp.hpp"
18
#include "Teuchos_CommHelpers.hpp"
19
20
21
namespace
Thyra {
22
23
24
// Consturctors/Initializers/Accessors
25
26
27
template
<
class
Scalar>
28
DiagonalScalarProd<Scalar>::DiagonalScalarProd
()
29
{}
30
31
32
template
<
class
Scalar>
33
void
DiagonalScalarProd<Scalar>::initialize
(
34
const
RCP
<
const
VectorBase<Scalar>
> &s_diag )
35
{
36
s_diag_ = s_diag.assert_not_null();
37
}
38
39
40
// Overridden from ScalarProdBase
41
42
43
template
<
class
Scalar>
44
bool
DiagonalScalarProd<Scalar>::isEuclideanImpl
()
const
45
{
46
return
false
;
47
}
48
49
50
template
<
class
Scalar>
51
void
DiagonalScalarProd<Scalar>::scalarProdsImpl
(
52
const
MultiVectorBase<Scalar>
& X,
const
MultiVectorBase<Scalar>
& Y,
53
const
ArrayView<Scalar>
&scalarProds_out )
const
54
{
55
56
using
Teuchos::as
;
57
typedef
Teuchos::ScalarTraits<Scalar>
ST;
58
59
const
Ordinal m = X.
domain
()->dim();
60
61
#ifdef TEUCHOS_DEBUG
62
THYRA_ASSERT_VEC_SPACES
(
"DiagonalScalarProd<Scalar>::scalarProds(X,Y,sclarProds)"
,
63
*s_diag_->space(), *Y.
range
() );
64
THYRA_ASSERT_VEC_SPACES
(
"DiagonalScalarProd<Scalar>::scalarProds(X,Y,sclarProds)"
,
65
*X.
range
(), *Y.
range
() );
66
THYRA_ASSERT_VEC_SPACES
(
"DiagonalScalarProd<Scalar>::scalarProds(X,Y,sclarProds)"
,
67
*X.
domain
(), *Y.
domain
() );
68
TEUCHOS_ASSERT_EQUALITY
( as<Ordinal>(scalarProds_out.
size
()), m );
69
#endif
70
71
const
ConstDetachedSpmdVectorView<Scalar>
s_diag(s_diag_);
72
73
const
RCP<const Teuchos::Comm<Ordinal>
> comm = s_diag.
spmdSpace
()->getComm();
74
75
for
(Ordinal j = 0; j < m; ++j) {
76
77
const
ConstDetachedSpmdVectorView<Scalar>
x(X.
col
(j));
78
const
ConstDetachedSpmdVectorView<Scalar>
y(Y.
col
(j));
79
80
Scalar scalarProd_j = ST::zero();
81
82
for
(Ordinal i = 0; i < x.
subDim
(); ++i) {
83
scalarProd_j += ST::conjugate(x[i]) * s_diag[i] * y[i];
84
}
85
86
if
(!is_null(comm)) {
87
Scalar g_scalarProd_j = 0.0;
88
Teuchos::reduceAll<Ordinal,Scalar>(
89
*comm, Teuchos::REDUCE_SUM,
90
scalarProd_j,
91
Teuchos::outArg(g_scalarProd_j)
92
);
93
scalarProds_out[j] = g_scalarProd_j;
94
}
95
else
{
96
scalarProds_out[j] = scalarProd_j;
97
}
98
99
}
100
101
}
102
103
104
template
<
class
Scalar>
105
RCP<const LinearOpBase<Scalar>
>
106
DiagonalScalarProd<Scalar>::getLinearOpImpl
()
const
107
{
108
TEUCHOS_TEST_FOR_EXCEPT_MSG
(
true
,
"ToDo: Implement when needed!"
)
109
TEUCHOS_UNREACHABLE_RETURN
(Teuchos::null);
110
}
111
112
113
}
// end namespace Thyra
114
115
116
#endif
// THYRA_DIAGONAL_SCALAR_PROD_DEF_HPP
Teuchos::ArrayView
Teuchos::ArrayView::size
size_type size() const
Teuchos::RCP
Thyra::ConstDetachedSpmdVectorView
Create an explicit detached non-mutable (const) view of all of the local elements on this process of ...
Definition
Thyra_DetachedSpmdVectorView.hpp:30
Thyra::ConstDetachedSpmdVectorView::subDim
Teuchos_Ordinal subDim() const
Definition
Thyra_DetachedSpmdVectorView.hpp:58
Thyra::ConstDetachedSpmdVectorView::spmdSpace
const RCP< const SpmdVectorSpaceBase< Scalar > > spmdSpace() const
Definition
Thyra_DetachedSpmdVectorView.hpp:51
Thyra::DiagonalScalarProd::scalarProdsImpl
virtual void scalarProdsImpl(const MultiVectorBase< Scalar > &X, const MultiVectorBase< Scalar > &Y, const ArrayView< Scalar > &scalarProds_out) const
Definition
Thyra_DiagonalScalarProd_def.hpp:51
Thyra::DiagonalScalarProd::isEuclideanImpl
virtual bool isEuclideanImpl() const
Returns false.
Definition
Thyra_DiagonalScalarProd_def.hpp:44
Thyra::DiagonalScalarProd::DiagonalScalarProd
DiagonalScalarProd()
Definition
Thyra_DiagonalScalarProd_def.hpp:28
Thyra::DiagonalScalarProd::initialize
void initialize(const RCP< const VectorBase< Scalar > > &s_diag)
Definition
Thyra_DiagonalScalarProd_def.hpp:33
Thyra::DiagonalScalarProd::getLinearOpImpl
RCP< const LinearOpBase< Scalar > > getLinearOpImpl() const
Definition
Thyra_DiagonalScalarProd_def.hpp:106
Thyra::LinearOpBase::range
virtual RCP< const VectorSpaceBase< Scalar > > range() const =0
Return a smart pointer for the range space for this operator.
Thyra::LinearOpBase::domain
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
Thyra::MultiVectorBase
Interface for a collection of column vectors called a multi-vector.
Definition
Thyra_MultiVectorBase_decl.hpp:464
Thyra::MultiVectorBase::col
RCP< const VectorBase< Scalar > > col(Ordinal j) const
Calls colImpl().
Definition
Thyra_MultiVectorBase_decl.hpp:609
Thyra::VectorBase
Abstract interface for finite-dimensional dense vectors.
Definition
Thyra_VectorBase.hpp:115
TEUCHOS_TEST_FOR_EXCEPT_MSG
#define TEUCHOS_TEST_FOR_EXCEPT_MSG(throw_exception_test, msg)
TEUCHOS_ASSERT_EQUALITY
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
THYRA_ASSERT_VEC_SPACES
#define THYRA_ASSERT_VEC_SPACES(FUNC_NAME, VS1, VS2)
This is a very useful macro that should be used to validate that two vector spaces are compatible.
Definition
Thyra_AssertOp.hpp:156
Teuchos::as
TypeTo as(const TypeFrom &t)
TEUCHOS_UNREACHABLE_RETURN
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
Teuchos::ScalarTraits
Generated by
1.17.0