EpetraExt  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EpetraExt_ProductOperator.h
Go to the documentation of this file.
1 //@HEADER
2 // ***********************************************************************
3 //
4 // EpetraExt: Epetra Extended - Linear Algebra Services Package
5 // Copyright (2011) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
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 Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 
42 #ifndef EPETRAEXT_PRODUCT_OPERATOR_H
43 #define EPETRAEXT_PRODUCT_OPERATOR_H
44 
45 #if defined(EpetraExt_SHOW_DEPRECATED_WARNINGS)
46 #ifdef __GNUC__
47 #warning "The EpetraExt package is deprecated"
48 #endif
49 #endif
50 
51 #include "Epetra_Operator.h"
52 #include "Teuchos_RCP.hpp"
53 #include "Teuchos_BLAS_types.hpp"
54 #include <vector>
55 
56 class Epetra_Vector;
57 
58 namespace EpetraExt {
59 
140 public:
141 
144 
147 
149 
152 
154  ProductOperator();
155 
158  const int num_Op
159  ,const Teuchos::RCP<const Epetra_Operator> Op[]
160  ,const Teuchos::ETransp Op_trans[]
161  ,const EApplyMode Op_inverse[]
162  );
163 
227  void initialize(
228  const int num_Op
229  ,const Teuchos::RCP<const Epetra_Operator> Op[]
230  ,const Teuchos::ETransp Op_trans[]
231  ,const EApplyMode Op_inverse[]
232  );
233 
240  void uninitialize(
241  int *num_Op
242  ,Teuchos::RCP<const Epetra_Operator> Op[]
243  ,Teuchos::ETransp Op_trans[]
244  ,EApplyMode p_inverse[]
245  );
246 
264  void applyConstituent(
265  const int k
266  ,Teuchos::ETransp Op_trans
268  ,const Epetra_MultiVector &X_k
269  ,Epetra_MultiVector *Y_k
270  ) const;
271 
277  int num_Op() const;
278 
290  Teuchos::RCP<const Epetra_Operator> Op(int k) const;
291 
298  Teuchos::ETransp Op_trans(int k) const;
299 
306  EApplyMode Op_inverse(int k) const;
307 
309 
312 
314  int SetUseTranspose(bool UseTranspose);
316  int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
318  int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
320  double NormInf() const;
322  const char * Label() const;
324  bool UseTranspose() const;
326  bool HasNormInf() const;
328  const Epetra_Comm & Comm() const;
330  const Epetra_Map & OperatorDomainMap() const;
332  const Epetra_Map & OperatorRangeMap() const;
333 
335 
336 private:
337 
338  // ////////////////////////////
339  // Private types
340 
341  typedef std::vector<Teuchos::RCP<const Epetra_Operator> > Op_t;
342  typedef std::vector<Teuchos::ETransp> Op_trans_t;
343  typedef std::vector<EApplyMode> Op_inverse_t;
344  typedef std::vector<Teuchos::RCP<Epetra_Vector> > EV_t;
345 
346  // ////////////////////////////
347  // Private data members
348 
349  bool UseTranspose_;
350  Op_t Op_;
351  Op_trans_t Op_trans_;
352  Op_inverse_t Op_inverse_;
353 
354  mutable EV_t range_vecs_;
355  mutable EV_t domain_vecs_;
356 
357  // ////////////////////////////
358  // Private member functions
359 
360  void assertInitialized() const;
361  void validateIndex(int k) const;
362  void initializeTempVecs(bool applyInverse) const;
363 
364 }; // class ProductOperator
365 
366 // ////////////////////////////
367 // Inline members
368 
369 // public
370 
371 inline
373 {
374  return Op_.size();
375 }
376 
377 inline
378 Teuchos::RCP<const Epetra_Operator>
380 {
381  validateIndex(k);
382  return Op_[k];
383 }
384 
385 inline
386 Teuchos::ETransp
388 {
389  validateIndex(k);
390  return Op_trans_[k];
391 }
392 
393 inline
396 {
397  validateIndex(k);
398  return Op_inverse_[k];
399 }
400 
401 
402 // private
403 
404 inline
405 void ProductOperator::assertInitialized() const
406 {
407  TEUCHOS_TEST_FOR_EXCEPTION(
408  Op_.size()==0, std::logic_error
409  ,"Epetra::ProductOperator: Error, Client has not called initialize(...) yet!"
410  );
411 }
412 
413 inline
414 void ProductOperator::validateIndex(int k) const
415 {
416  TEUCHOS_TEST_FOR_EXCEPTION(
417  k < 0 || static_cast<int>(Op_.size())-1 < k, std::logic_error
418  ,"Epetra::ProductOperator: Error, k = "<<k<< " is not in the range [0,"<<Op_.size()-1<<"]!"
419  );
420 }
421 
422 } // namespace EpetraExt
423 
424 #endif // EPETRAEXT_PRODUCT_OPERATOR_H
const Epetra_Map & OperatorDomainMap() const
void initialize(const int num_Op, const Teuchos::RCP< const Epetra_Operator > Op[], const Teuchos::ETransp Op_trans[], const EApplyMode Op_inverse[])
Setup with constituent operators.
Implements Epetra_Operator as a product of one or more Epetra_Operator objects.
int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
ProductOperator()
Construct to uninitialized.
const Epetra_Comm & Comm() const
int num_Op() const
Return the number of aggregate opeators.
const Epetra_Map & OperatorRangeMap() const
Teuchos::RCP< const Epetra_Operator > Op(int k) const
Access the kth operator (zero-based).
Teuchos::ETransp Op_trans(int k) const
Access the transpose mode of the kth operator (zero-based).
int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
EApplyMode Op_inverse(int k) const
Access the inverse mode of the kth operator (zero-based).
void uninitialize(int *num_Op, Teuchos::RCP< const Epetra_Operator > Op[], Teuchos::ETransp Op_trans[], EApplyMode p_inverse[])
Set to an uninitialized state and wipe out memory.
void applyConstituent(const int k, Teuchos::ETransp Op_trans, EApplyMode Op_inverse, const Epetra_MultiVector &X_k, Epetra_MultiVector *Y_k) const
Apply the kth aggregate operator M[k] correctly.