Thyra Version of the Day
Loading...
Searching...
No Matches
Thyra_describeLinearOp_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_DESCRIBE_LINEAR_OP_HPP
11#define THYRA_DESCRIBE_LINEAR_OP_HPP
12
13#include "Thyra_LinearOpBase.hpp"
14#include "Thyra_MultiVectorBase.hpp"
15#include "Thyra_VectorStdOps.hpp"
16#include "Thyra_AssertOp.hpp"
17
18
19template<class Scalar>
20void Thyra::describeLinearOp(
21 const LinearOpBase<Scalar> &A,
22 Teuchos::FancyOStream &out_arg,
23 const Teuchos::EVerbosityLevel verbLevel
24 )
25{
26 using Teuchos::RCP;
28 using Teuchos::OSTab;
30
31 RCP<FancyOStream> out = rcp(&out_arg,false);
32 OSTab tab(out);
33 *out << A.description() << "\n";
34
36 range = A.range();
38 domain = A.domain();
39
40 if(!range.get()) {
41 return;
42 }
43
44 const Ordinal dimDomain = domain->dim(), dimRange = range->dim();
45 if ( dimDomain > 0 && dimRange > 0 && verbLevel >= Teuchos::VERB_EXTREME ) {
46 // Copy into dense matrix by column
47 Teuchos::RCP<VectorBase<Scalar> > e_j = createMember(domain);
48 Teuchos::RCP<VectorBase<Scalar> > t = createMember(range); // temp column
50 Array<Scalar> Md(dimRange*dimDomain); // Column major
51 const Ordinal
52 cs = 1, // stride for columns or rows
53 rs = dimRange; // stride for rows or columns
54 Ordinal i, j;
55 OSTab tab2(out);
56 for( j = 0; j < dimDomain; ++j ) {
57 Thyra::assign( e_j.ptr(), DST::zero() );
58 Thyra::set_ele( j, DST::one(), e_j.ptr() );
59 Thyra::apply<Scalar>(A, NOTRANS, *e_j, t.ptr()); // extract the ith column or row
60 t->acquireDetachedView(Range1D(),&sv);
61 for( i = 0; i < dimRange; ++i ) Md[ i*cs + j*rs ] = sv(i);
62 t->releaseDetachedView(&sv);
63 }
64 // Print the matrix
65 for( i = 0; i < dimRange; ++i ) {
66 for( j = 0; j < dimDomain; ++j )
67 *out << " " << i << ":" << j << ":" << Md[ i + j*dimRange ];
68 *out << std::endl;
69 }
70 }
71
72}
73
74
75//
76// Explicit instant macro
77//
78
79#define THYRA_DESCRIBE_LINEAR_INSTANT(SCALAR) \
80 \
81 template void describeLinearOp( \
82 const LinearOpBase<SCALAR > &A, \
83 Teuchos::FancyOStream &out_arg, \
84 const Teuchos::EVerbosityLevel verbLevel \
85 ); \
86
87
88
89#endif // THYRA_DESCRIBE_LINEAR_OP_HPP
Ptr< T > ptr() const
T * get() const
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Teuchos::Range1D Range1D
basic_OSTab< char > OSTab
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)