Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_BasicMappingStrategy.cpp
1 // @HEADER
2 // *****************************************************************************
3 // Teko: A package for block and physics based preconditioning
4 //
5 // Copyright 2010 NTESS and the Teko contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Epetra/Teko_BasicMappingStrategy.hpp"
11 #include "Epetra/Teko_EpetraHelpers.hpp"
12 
13 #include "Thyra_EpetraThyraWrappers.hpp"
14 #include "Thyra_DefaultSpmdMultiVector.hpp"
15 
16 using Teuchos::RCP;
17 using Teuchos::rcp;
18 using Teuchos::rcp_dynamic_cast;
19 
20 namespace Teko {
21 namespace Epetra {
22 
23 // Creates a strided mapping strategy. This class is useful
24 // for breaking up nodally ordered matrices (i.e. the unknowns
25 // in a FEM problem are ordered [u0,v0,p0,u1,v1,p1,...]). Current
26 // implimentation only supports a fixed number of variables
27 //
28 // arguments:
29 // vars - Number of different variables
30 // map - original Epetra_Map to be broken up
31 // comm - Epetra_Comm object related to the map
32 //
33 BasicMappingStrategy::BasicMappingStrategy(const Teuchos::RCP<const Epetra_Map>& rMap,
34  const Teuchos::RCP<const Epetra_Map>& dMap,
35  const Epetra_Comm& /* comm */) {
36  rangeMap_ = rMap;
37  domainMap_ = dMap;
38 }
39 
40 // Virtual function defined in MappingStrategy. This copies
41 // an Epetra_MultiVector into a Thyra::MultiVectorBase with
42 // blocking handled by the strides defined in the constructor.
43 //
44 // arguments:
45 // X - source Epetra_MultiVector
46 // thyra_X - destination Thyra::MultiVectorBase
47 //
48 void BasicMappingStrategy::copyEpetraIntoThyra(
49  const Epetra_MultiVector& X,
50  const Teuchos::Ptr<Thyra::MultiVectorBase<double> >& thyra_X) const {
51  // perform a simple copy
52  RCP<Thyra::DefaultSpmdMultiVector<double> > vec =
53  rcp_dynamic_cast<Thyra::DefaultSpmdMultiVector<double> >(Teuchos::rcpFromRef(*thyra_X));
54  Teuchos::RCP<Epetra_MultiVector> ptrX =
55  Teuchos::rcp_const_cast<Epetra_MultiVector>(Teuchos::rcpFromRef(X));
56  fillDefaultSpmdMultiVector(vec, ptrX);
57 }
58 
59 // Virtual function defined in MappingStrategy. This copies
60 // an Epetra_MultiVector into a Thyra::MultiVectorBase with
61 // blocking handled by the strides defined in the constructor.
62 //
63 // arguments:
64 // thyra_Y - source Thyra::MultiVectorBase
65 // Y - destination Epetra_MultiVector
66 //
67 void BasicMappingStrategy::copyThyraIntoEpetra(
68  const RCP<const Thyra::MultiVectorBase<double> >& thyra_Y, Epetra_MultiVector& Y) const {
69  RCP<const Epetra_MultiVector> eSrc = Thyra::get_Epetra_MultiVector(*rangeMap(), thyra_Y);
70 
71  Y = *eSrc;
72 }
73 
74 } // end namespace Epetra
75 } // end namespace Teko