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#include "Thyra_AssertOp.hpp"
18
19
20template<class Scalar>
21void Thyra::describeLinearOp(
22 const LinearOpBase<Scalar> &A,
23 Teuchos::FancyOStream &out_arg,
24 const Teuchos::EVerbosityLevel verbLevel
25 )
26{
27 using Teuchos::RCP;
29 using Teuchos::OSTab;
31
32 RCP<FancyOStream> out = rcp(&out_arg,false);
33 OSTab tab(out);
34 *out << A.description() << "\n";
35
37 range = A.range();
39 domain = A.domain();
40
41 if(!range.get()) {
42 return;
43 }
44
45 const Ordinal dimDomain = domain->dim(), dimRange = range->dim();
46 if ( dimDomain > 0 && dimRange > 0 && verbLevel >= Teuchos::VERB_EXTREME ) {
47 // Copy into dense matrix by column
48 Teuchos::RCP<VectorBase<Scalar> > e_j = createMember(domain);
49 Teuchos::RCP<VectorBase<Scalar> > t = createMember(range); // temp column
51 Array<Scalar> Md(dimRange*dimDomain); // Column major
52 const Ordinal
53 cs = 1, // stride for columns or rows
54 rs = dimRange; // stride for rows or columns
55 Ordinal i, j;
56 OSTab tab2(out);
57 for( j = 0; j < dimDomain; ++j ) {
58 Thyra::assign( e_j.ptr(), DST::zero() );
59 Thyra::set_ele( j, DST::one(), e_j.ptr() );
60 Thyra::apply<Scalar>(A, NOTRANS, *e_j, t.ptr()); // extract the ith column or row
61 t->acquireDetachedView(Range1D(),&sv);
62 for( i = 0; i < dimRange; ++i ) Md[ i*cs + j*rs ] = sv(i);
63 t->releaseDetachedView(&sv);
64 }
65 // Print the matrix
66 for( i = 0; i < dimRange; ++i ) {
67 for( j = 0; j < dimDomain; ++j )
68 *out << " " << i << ":" << j << ":" << Md[ i + j*dimRange ];
69 *out << std::endl;
70 }
71 }
72
73}
74
75
76//
77// Explicit instant macro
78//
79
80#define THYRA_DESCRIBE_LINEAR_INSTANT(SCALAR) \
81 \
82 template void describeLinearOp( \
83 const LinearOpBase<SCALAR > &A, \
84 Teuchos::FancyOStream &out_arg, \
85 const Teuchos::EVerbosityLevel verbLevel \
86 ); \
87
88
89
90#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)