Thyra
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
core
test
nonlinear
models
Thyra_DiagonalScalarProd_def.hpp
1
/*
2
// @HEADER
3
// ***********************************************************************
4
//
5
// Thyra: Interfaces and Support for Abstract Numerical Algorithms
6
// Copyright (2004) Sandia Corporation
7
//
8
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9
// license for use of this work by or on behalf of the U.S. Government.
10
//
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are
13
// met:
14
//
15
// 1. Redistributions of source code must retain the above copyright
16
// notice, this list of conditions and the following disclaimer.
17
//
18
// 2. Redistributions in binary form must reproduce the above copyright
19
// notice, this list of conditions and the following disclaimer in the
20
// documentation and/or other materials provided with the distribution.
21
//
22
// 3. Neither the name of the Corporation nor the names of the
23
// contributors may be used to endorse or promote products derived from
24
// this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
//
38
// Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
39
//
40
// ***********************************************************************
41
// @HEADER
42
*/
43
44
#ifndef THYRA_DIAGONAL_SCALAR_PROD_DEF_HPP
45
#define THYRA_DIAGONAL_SCALAR_PROD_DEF_HPP
46
47
48
#include "Thyra_DiagonalScalarProd_decl.hpp"
49
#include "Thyra_DetachedSpmdVectorView.hpp"
50
#include "Thyra_SpmdVectorSpaceBase.hpp"
51
#include "Thyra_AssertOp.hpp"
52
#include "Teuchos_CommHelpers.hpp"
53
54
55
namespace
Thyra {
56
57
58
// Consturctors/Initializers/Accessors
59
60
61
template
<
class
Scalar>
62
DiagonalScalarProd<Scalar>::DiagonalScalarProd
()
63
{}
64
65
66
template
<
class
Scalar>
67
void
DiagonalScalarProd<Scalar>::initialize
(
68
const
RCP
<
const
VectorBase<Scalar>
> &s_diag )
69
{
70
s_diag_ = s_diag.assert_not_null();
71
}
72
73
74
// Overridden from ScalarProdBase
75
76
77
template
<
class
Scalar>
78
bool
DiagonalScalarProd<Scalar>::isEuclideanImpl
()
const
79
{
80
return
false
;
81
}
82
83
84
template
<
class
Scalar>
85
void
DiagonalScalarProd<Scalar>::scalarProdsImpl
(
86
const
MultiVectorBase<Scalar>
& X,
const
MultiVectorBase<Scalar>
& Y,
87
const
ArrayView<Scalar>
&scalarProds_out )
const
88
{
89
90
using
Teuchos::as
;
91
typedef
Teuchos::ScalarTraits<Scalar>
ST;
92
93
const
Ordinal m = X.
domain
()->dim();
94
95
#ifdef TEUCHOS_DEBUG
96
THYRA_ASSERT_VEC_SPACES
(
"DiagonalScalarProd<Scalar>::scalarProds(X,Y,sclarProds)"
,
97
*s_diag_->space(), *Y.
range
() );
98
THYRA_ASSERT_VEC_SPACES
(
"DiagonalScalarProd<Scalar>::scalarProds(X,Y,sclarProds)"
,
99
*X.
range
(), *Y.
range
() );
100
THYRA_ASSERT_VEC_SPACES
(
"DiagonalScalarProd<Scalar>::scalarProds(X,Y,sclarProds)"
,
101
*X.
domain
(), *Y.
domain
() );
102
TEUCHOS_ASSERT_EQUALITY
( as<Ordinal>(scalarProds_out.
size
()), m );
103
#endif
104
105
const
ConstDetachedSpmdVectorView<Scalar>
s_diag(s_diag_);
106
107
const
RCP<const Teuchos::Comm<Ordinal>
> comm = s_diag.
spmdSpace
()->getComm();
108
109
for
(Ordinal j = 0; j < m; ++j) {
110
111
const
ConstDetachedSpmdVectorView<Scalar>
x(X.
col
(j));
112
const
ConstDetachedSpmdVectorView<Scalar>
y(Y.
col
(j));
113
114
Scalar scalarProd_j = ST::zero();
115
116
for
(Ordinal i = 0; i < x.
subDim
(); ++i) {
117
scalarProd_j += ST::conjugate(x[i]) * s_diag[i] * y[i];
118
}
119
120
if
(!is_null(comm)) {
121
Scalar g_scalarProd_j = 0.0;
122
Teuchos::reduceAll<Ordinal,Scalar>(
123
*comm, Teuchos::REDUCE_SUM,
124
scalarProd_j,
125
Teuchos::outArg(g_scalarProd_j)
126
);
127
scalarProds_out[j] = g_scalarProd_j;
128
}
129
else
{
130
scalarProds_out[j] = scalarProd_j;
131
}
132
133
}
134
135
}
136
137
138
template
<
class
Scalar>
139
RCP<const LinearOpBase<Scalar>
>
140
DiagonalScalarProd<Scalar>::getLinearOpImpl
()
const
141
{
142
TEUCHOS_TEST_FOR_EXCEPT_MSG
(
true
,
"ToDo: Implement when needed!"
)
143
TEUCHOS_UNREACHABLE_RETURN
(Teuchos::null);
144
}
145
146
147
}
// end namespace Thyra
148
149
150
#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:62
Thyra::ConstDetachedSpmdVectorView::subDim
Teuchos_Ordinal subDim() const
Definition
Thyra_DetachedSpmdVectorView.hpp:90
Thyra::ConstDetachedSpmdVectorView::spmdSpace
const RCP< const SpmdVectorSpaceBase< Scalar > > spmdSpace() const
Definition
Thyra_DetachedSpmdVectorView.hpp:83
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:85
Thyra::DiagonalScalarProd::isEuclideanImpl
virtual bool isEuclideanImpl() const
Returns false.
Definition
Thyra_DiagonalScalarProd_def.hpp:78
Thyra::DiagonalScalarProd::DiagonalScalarProd
DiagonalScalarProd()
Definition
Thyra_DiagonalScalarProd_def.hpp:62
Thyra::DiagonalScalarProd::initialize
void initialize(const RCP< const VectorBase< Scalar > > &s_diag)
Definition
Thyra_DiagonalScalarProd_def.hpp:67
Thyra::DiagonalScalarProd::getLinearOpImpl
RCP< const LinearOpBase< Scalar > > getLinearOpImpl() const
Definition
Thyra_DiagonalScalarProd_def.hpp:140
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:496
Thyra::MultiVectorBase::col
RCP< const VectorBase< Scalar > > col(Ordinal j) const
Calls colImpl().
Definition
Thyra_MultiVectorBase_decl.hpp:641
Thyra::VectorBase
Abstract interface for finite-dimensional dense vectors.
Definition
Thyra_VectorBase.hpp:147
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:188
Teuchos::as
TypeTo as(const TypeFrom &t)
TEUCHOS_UNREACHABLE_RETURN
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
Teuchos::ScalarTraits
Generated by
1.17.0