Tpetra parallel linear algebra  Version of the Day
Tpetra_FEMultiVector_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) 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 TPETRA_FEMULTIVECTOR_DECL_HPP
43 #define TPETRA_FEMULTIVECTOR_DECL_HPP
44 
53 
56 
57 namespace Tpetra {
58 namespace Classes {
59 
60  template <class Scalar = ::Tpetra::Details::DefaultTypes::scalar_type,
62  class GlobalOrdinal = ::Tpetra::Details::DefaultTypes::global_ordinal_type,
64  class FEMultiVector :
65  public MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>
66  {
67  private:
68  friend ::Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
69  public:
71 
72 
74  typedef Scalar scalar_type;
76  typedef LocalOrdinal local_ordinal_type;
78  typedef GlobalOrdinal global_ordinal_type;
80  typedef Node node_type;
81 
84 
87 
90 
93 
96 
99 
102 
104  typedef MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> base_type;
105 
107 
109  // NOTE: A map AND an importer need to be arguments because in serial, the importer will be null
118  // This will default to importer->getTargetMap() being the active MultiVector
119  FEMultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & map,
120  const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> >& importer,
121  const size_t numVecs,
122  const bool zeroOut = true);
123 
125  virtual ~FEMultiVector () {}
126 
128 
130 
131  // ! Calls endFill()
132  void globalAssemble() {endFill();}
133 
135  void endFill()
136  {
137  if(*activeMultiVector_ == FE_ACTIVE_TARGET) {
138  doTargetToSource(Tpetra::ADD);
139  switchActiveMultiVector();
140  }
141  else
142  throw std::runtime_error("FEMultiVector: Source MultiVector already active. Cannot endFill()");
143  }
144 
146  void beginFill()
147  {
148  // Note: This does not throw an error since the on construction, the FEMV is in target mode. Ergo, calling beginFill(),
149  // like one should expect to do in a rational universe, should not cause an error.
150  if(*activeMultiVector_ == FE_ACTIVE_SOURCE) {
151  switchActiveMultiVector();
152  }
153  }
154 
155 
157  // Since this is non-unique -> unique, we need a combine mode.
158  // Precondition: Target MultiVector must be active
159  void doTargetToSource(const CombineMode CM=Tpetra::ADD);
160 
161 
163  // Precondition: Source MultiVector must be active
164  void doSourceToTarget(const CombineMode CM=Tpetra::ADD);
165 
167  void switchActiveMultiVector();
168 
169  private:
171  FEMultiVector() = delete;
172 
173  protected:
175 
181  void replaceMap (const Teuchos::RCP<const map_type>& map);
182 
183  // Enum for activity
184  enum FEWhichActive
185  {
186  FE_ACTIVE_TARGET,
187  FE_ACTIVE_SOURCE
188  };
189 
190 
191  // This is whichever multivector isn't currently active
192  Teuchos::RCP< MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > inactiveMultiVector_;
193  // This is in RCP to make shallow copies of the FEMultiVector work correctly
194  Teuchos::RCP<FEWhichActive> activeMultiVector_;
195 
196  // Importer
197  Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > importer_;
198 
200  }; // class FEMultiVector
201 
202 } // namespace Classes
203 } // namespace Tpetra
204 
205 #endif // TPETRA_FEMULTIVECTOR_DECL_HPP
Tpetra::Classes::MultiVector::map_type
Map< LocalOrdinal, GlobalOrdinal, Node > map_type
The type of the Map specialization used by this class.
Definition: Tpetra_MultiVector_decl.hpp:479
Tpetra_MultiVector_decl.hpp
Declaration of the Tpetra::MultiVector class.
Tpetra::Details::DefaultTypes::node_type
::Kokkos::Compat::KokkosDeviceWrapperNode< execution_space > node_type
Default value of Node template parameter.
Definition: Tpetra_Details_DefaultTypes.hpp:105
Tpetra::Classes::MultiVector::device_type
Node::device_type device_type
The Kokkos device type.
Definition: Tpetra_MultiVector_decl.hpp:423
Tpetra::MultiVector
Classes::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > MultiVector
Alias for Tpetra::Classes::MultiVector.
Definition: Tpetra_MultiVector_fwd.hpp:72
Tpetra::Classes::MultiVector::dual_view_type
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutLeft, typename execution_space::execution_space > dual_view_type
Kokkos::DualView specialization used by this class.
Definition: Tpetra_MultiVector_decl.hpp:476
Tpetra::Classes::MultiVector::execution_space
Node::execution_space execution_space
Type of the (new) Kokkos execution space.
Definition: Tpetra_MultiVector_decl.hpp:451
Tpetra::ADD
Sum new values into existing values.
Definition: Tpetra_CombineMode.hpp:95
Tpetra::Classes::MultiVector::mag_type
Kokkos::Details::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
Definition: Tpetra_MultiVector_decl.hpp:443
Tpetra::FEMultiVector
Classes::FEMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > FEMultiVector
Alias for Tpetra::Classes::FEMultiVector.
Definition: Tpetra_FEMultiVector_fwd.hpp:72
Tpetra::Details::DefaultTypes::local_ordinal_type
int local_ordinal_type
Default value of Scalar template parameter.
Definition: Tpetra_Details_DefaultTypes.hpp:72
Tpetra::Classes::MultiVector::dot_type
Kokkos::Details::InnerProductSpaceTraits< impl_scalar_type >::dot_type dot_type
Type of an inner ("dot") product result.
Definition: Tpetra_MultiVector_decl.hpp:435
Tpetra::Classes::MultiVector::impl_scalar_type
Kokkos::Details::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
Definition: Tpetra_MultiVector_decl.hpp:414
Tpetra
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Tpetra_FEMultiVector_fwd.hpp
Forward declaration of Tpetra::FEMultiVector.
Tpetra::CombineMode
CombineMode
Rule for combining data in an Import or Export.
Definition: Tpetra_CombineMode.hpp:94