Thyra
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
core
src
support
operator_vector
client_support
Thyra_describeLinearOp_def.hpp
1
// @HEADER
2
// ***********************************************************************
3
//
4
// Thyra: Interfaces and Support for Abstract Numerical Algorithms
5
// Copyright (2004) Sandia Corporation
6
//
7
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8
// license for use of this work by or on behalf of the U.S. Government.
9
//
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are
12
// met:
13
//
14
// 1. Redistributions of source code must retain the above copyright
15
// notice, this list of conditions and the following disclaimer.
16
//
17
// 2. Redistributions in binary form must reproduce the above copyright
18
// notice, this list of conditions and the following disclaimer in the
19
// documentation and/or other materials provided with the distribution.
20
//
21
// 3. Neither the name of the Corporation nor the names of the
22
// contributors may be used to endorse or promote products derived from
23
// this software without specific prior written permission.
24
//
25
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
//
37
// Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38
//
39
// ***********************************************************************
40
// @HEADER
41
42
#ifndef THYRA_DESCRIBE_LINEAR_OP_HPP
43
#define THYRA_DESCRIBE_LINEAR_OP_HPP
44
45
#include "Thyra_describeLinearOp_def.hpp"
46
#include "Thyra_LinearOpBase.hpp"
47
#include "Thyra_MultiVectorBase.hpp"
48
#include "Thyra_VectorStdOps.hpp"
49
#include "Thyra_AssertOp.hpp"
50
#include "Thyra_AssertOp.hpp"
51
52
53
template
<
class
Scalar>
54
void
Thyra::describeLinearOp(
55
const
LinearOpBase<Scalar> &A,
56
Teuchos::FancyOStream
&out_arg,
57
const
Teuchos::EVerbosityLevel
verbLevel
58
)
59
{
60
using
Teuchos::RCP
;
61
using
Teuchos::FancyOStream
;
62
using
Teuchos::OSTab
;
63
typedef
Teuchos::ScalarTraits<Scalar>
DST;
64
65
RCP<FancyOStream> out =
rcp
(&out_arg,
false
);
66
OSTab
tab(out);
67
*out << A.description() <<
"\n"
;
68
69
const
Teuchos::RCP<const VectorSpaceBase<Scalar>
>
70
range = A.range();
71
const
Teuchos::RCP<const VectorSpaceBase<Scalar>
>
72
domain = A.domain();
73
74
if
(!range.
get
()) {
75
return
;
76
}
77
78
const
Ordinal dimDomain = domain->dim(), dimRange = range->dim();
79
if
( dimDomain > 0 && dimRange > 0 && verbLevel >=
Teuchos::VERB_EXTREME
) {
80
// Copy into dense matrix by column
81
Teuchos::RCP<VectorBase<Scalar>
> e_j =
createMember
(domain);
82
Teuchos::RCP<VectorBase<Scalar>
> t =
createMember
(range);
// temp column
83
RTOpPack::ConstSubVectorView<Scalar>
sv;
84
Array<Scalar> Md(dimRange*dimDomain);
// Column major
85
const
Ordinal
86
cs = 1,
// stride for columns or rows
87
rs = dimRange;
// stride for rows or columns
88
Ordinal i, j;
89
OSTab
tab2(out);
90
for
( j = 0; j < dimDomain; ++j ) {
91
Thyra::assign
( e_j.
ptr
(), DST::zero() );
92
Thyra::set_ele
( j, DST::one(), e_j.
ptr
() );
93
Thyra::apply<Scalar>
(A, NOTRANS, *e_j, t.
ptr
());
// extract the ith column or row
94
t->acquireDetachedView(
Range1D
(),&sv);
95
for
( i = 0; i < dimRange; ++i ) Md[ i*cs + j*rs ] = sv(i);
96
t->releaseDetachedView(&sv);
97
}
98
// Print the matrix
99
for
( i = 0; i < dimRange; ++i ) {
100
for
( j = 0; j < dimDomain; ++j )
101
*out <<
" "
<< i <<
":"
<< j <<
":"
<< Md[ i + j*dimRange ];
102
*out << std::endl;
103
}
104
}
105
106
}
107
108
109
//
110
// Explicit instant macro
111
//
112
113
#define THYRA_DESCRIBE_LINEAR_INSTANT(SCALAR) \
114
\
115
template void describeLinearOp( \
116
const LinearOpBase<SCALAR > &A, \
117
Teuchos::FancyOStream &out_arg, \
118
const Teuchos::EVerbosityLevel verbLevel \
119
); \
120
121
122
123
#endif
// THYRA_DESCRIBE_LINEAR_OP_HPP
RTOpPack::ConstSubVectorView
Teuchos::RCP
Teuchos::RCP::ptr
Ptr< T > ptr() const
Teuchos::RCP::get
T * get() const
Thyra::LinearOpBase::apply
void apply(const LinearOpBase< Scalar > &M, const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha=static_cast< Scalar >(1.0), const Scalar beta=static_cast< Scalar >(0.0))
Non-member function call for M.apply(...).
Definition
Thyra_LinearOpBase_def.hpp:73
Thyra::MultiVectorBase::assign
void assign(const Ptr< MultiVectorBase< Scalar > > &V, Scalar alpha)
V = alpha.
Definition
Thyra_MultiVectorStdOps_def.hpp:154
Thyra::VectorBase::set_ele
void set_ele(Ordinal i, Scalar alpha, const Ptr< VectorBase< Scalar > > &v)
Set single element: v(i) = alpha.
Definition
Thyra_VectorStdOps_def.hpp:153
Thyra::VectorSpaceBase::createMember
RCP< VectorBase< Scalar > > createMember(const RCP< const VectorSpaceBase< Scalar > > &vs, const std::string &label="")
Create a vector member from the vector space.
Thyra::Range1D
Teuchos::Range1D Range1D
Definition
Thyra_OperatorVectorTypes.hpp:97
Teuchos::FancyOStream
basic_FancyOStream< char > FancyOStream
Teuchos::OSTab
basic_OSTab< char > OSTab
Teuchos::EVerbosityLevel
EVerbosityLevel
Teuchos::VERB_EXTREME
VERB_EXTREME
Teuchos::rcp
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::ScalarTraits
Generated by
1.17.0