Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_Transform.hpp
1// @HEADER
2// *****************************************************************************
3// Tpetra: Templated Linear Algebra Services Package
4//
5// Copyright 2008 NTESS and the Tpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TPETRA_TRANSFORM_HPP
11#define TPETRA_TRANSFORM_HPP
12
15
16#include <Teuchos_RCP.hpp>
17#include <Teuchos_GlobalMPISession.hpp>
18
19namespace Tpetra {
20
22
29template <typename T, typename U>
30class Transform {
31 public:
34
35 using OriginalType = Teuchos::RCP<T>;
36 using OriginalConstType = Teuchos::RCP<const T>;
37 using NewType = Teuchos::RCP<U>;
38 using NewConstType = Teuchos::RCP<const U>;
39
41
43 virtual ~Transform() = default;
44
47
52 virtual NewType operator()(const OriginalType& orig) = 0;
53
59 virtual void fwd() = 0;
60
66 virtual void rvs() = 0;
67
69
73
83 virtual void analyze(const OriginalType& orig);
84
88 virtual NewType construct();
89
94 virtual bool isConstructed();
95
97
98 protected:
106 : origObj_(Teuchos::null)
107 , newObj_(Teuchos::null) {}
108
109 OriginalType origObj_;
110 NewType newObj_;
111
112 private:
113 Transform(const Transform<T, U>& src)
114 : origObj_(src.origObj_)
115 , newObj_(src.newObj_) {}
116
117 Transform<T, U>& operator=(const Transform<T, U>& src) {
118 // Not currently supported.
119 Teuchos::GlobalMPISession::abort();
120 return (*this);
121 }
122
123}; // end class Transform
124
125template <typename T, typename U>
127 analyze(const OriginalType& orig) {
128 origObj_ = orig;
129 newObj_ = Teuchos::rcp_dynamic_cast<U>(origObj_);
130 return;
131}
132
133template <typename T, typename U>
134typename Transform<T, U>::NewType
136 construct() {
137 return newObj_;
138}
139
140template <typename T, typename U>
143 return (newObj_ != Teuchos::null);
144}
145
146template <typename T, typename U>
147class StructuralTransform : public Transform<T, U> {
148 public:
149 void fwd() { return; }
150 void rvs() { return; }
151
152 virtual ~StructuralTransform() = default;
153};
154
155template <typename T>
156class SameTypeTransform : public Transform<T, T> {
157 public:
158 using TransformType = Teuchos::RCP<T>;
159
160 virtual ~SameTypeTransform() = default;
161};
162
163template <typename T>
164class StructuralSameTypeTransform : public SameTypeTransform<T> {
165 public:
166 void fwd() { return; }
167 void rvs() { return; }
168
169 virtual ~StructuralSameTypeTransform() = default;
170};
171
172// template<typename T>
173// class InPlaceTransform : public SameTypeTransform<T>
174// {
175// public:
176// typename Transform<T,T>::NewTypeRef
177// operator()
178// ( typename Transform<T,T>::OriginalTypeRef orig )
179// { this->origObj_ = &orig;
180// this->newObj_ = &orig;
181// return orig;
182// }
183//
184// virtual ~InPlaceTransform() = default;
185// };
186
187template <typename T>
188class ViewTransform : public SameTypeTransform<T> {
189 public:
190 void fwd() { return; }
191 void rvs() { return; }
192
193 virtual ~ViewTransform() = default;
194};
195
196} // namespace Tpetra
197
198#endif // TPETRA_TRANSFORM_HPP
Struct that holds views of the contents of a CrsMatrix.
Transform()
Default constructor.
virtual bool isConstructed()
Check if transformed object has been constructed.
virtual void fwd()=0
Forward transfer of data.
virtual NewType construct()
Construction of new object as a result of the transform.
virtual void rvs()=0
Reverse transfer of data.
virtual NewType operator()(const OriginalType &orig)=0
Analysis of transform operation on original object and construction of new object.
virtual void analyze(const OriginalType &orig)
Initial analysis phase of transform.
Namespace Tpetra contains the class and methods constituting the Tpetra library.