NimbleSM
NimbleSM is a solid mechanics simulation code for dynamic systems
Loading...
Searching...
No Matches
nimble_tpetra_utils.h
Go to the documentation of this file.
1/*
2//@HEADER
3// ************************************************************************
4//
5// NimbleSM
6// Copyright 2018
7// National Technology & Engineering Solutions of Sandia, LLC (NTESS)
8//
9// Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government
10// retains certain rights in this software.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are
14// met:
15//
16// 1. Redistributions of source code must retain the above copyright
17// notice, this list of conditions and the following disclaimer.
18//
19// 2. Redistributions in binary form must reproduce the above copyright
20// notice, this list of conditions and the following disclaimer in the
21// documentation and/or other materials provided with the distribution.
22//
23// 3. Neither the name of the Corporation nor the names of the
24// contributors may be used to endorse or promote products derived from
25// this software without specific prior written permission.
26//
27// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY EXPRESS OR IMPLIED
28// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
30// NO EVENT SHALL NTESS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
32// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact David Littlewood (djlittl@sandia.gov)
39//
40// ************************************************************************
41//@HEADER
42*/
43
44#ifndef NIMBLE_TPETRA_UTILS_H
45#define NIMBLE_TPETRA_UTILS_H
46
47#include <string>
48#include <vector>
49
50#ifdef NIMBLE_HAVE_TRILINOS
51#include <Teuchos_GlobalMPISession.hpp>
52#include <Teuchos_oblackholestream.hpp>
53#include <Tpetra_Core.hpp>
54#include <Tpetra_CrsMatrix.hpp>
55#include <Tpetra_TieBreak.hpp>
56#include <Tpetra_Vector.hpp>
57#endif
58
59#include "nimble_macros.h"
60
61// TODO
62// Move the matrix contain class to nimble_linear_solver.h
63// Modify accessor routines for all matrix container classes to be as compatible
64// as possible with CrsMatrix Implement row-wise inserts, to be as efficient as
65// possible for the epetra case (probably all cases)
66
67namespace nimble {
68
69class GenesisMesh;
70class ModelData;
71
72#ifdef NIMBLE_HAVE_TRILINOS
73typedef Teuchos::RCP<const Teuchos::Comm<int>> comm_type;
74#else
75typedef int comm_type;
76#endif
77
78template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal>
80{
81 public:
83
85
86#ifdef NIMBLE_HAVE_TRILINOS
87
88 explicit TpetraMatrixContainer(Teuchos::RCP<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal>> crs_matrix)
89 : crs_matrix_(crs_matrix)
90 {
91 }
92
93 bool
94 SumIntoValue(LocalOrdinal local_row_index, GlobalOrdinal local_col_index, Scalar value)
95 {
96 auto local_row = static_cast<LocalOrdinal>(local_row_index);
97 Teuchos::ArrayRCP<LocalOrdinal> local_cols;
98 Teuchos::ArrayRCP<Scalar> values;
99
100 LocalOrdinal success = crs_matrix_->sumIntoLocalValues(local_row, local_cols(), values());
101
102 if (success == Teuchos::OrdinalTraits<LocalOrdinal>::invalid()) {
104 "\nError in TpetraMatrixContainer::sumIntoValue(), "
105 "replaceLocalValues() failed.\n");
106 } else if (success != 1) {
107 NIMBLE_ABORT("\nError in TpetraMatrixContainer::sumIntoValue(), invalid index.\n");
108 }
109 std::cout << "DJL DEBUGGING TpetraMatrixContainer::sumIntoValue() success! " << success << std::endl;
110 }
111
112 private:
113 Teuchos::RCP<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal>> crs_matrix_;
114
115#endif
116};
117
119{
120 public:
121#ifdef NIMBLE_HAVE_TRILINOS
122 typedef Tpetra::Map<> map_type;
123 typedef Tpetra::Vector<> vector_type;
124 typedef Tpetra::Vector<>::scalar_type scalar_type;
125 typedef Tpetra::Vector<>::local_ordinal_type local_ordinal_type;
126 typedef Tpetra::Vector<>::global_ordinal_type global_ordinal_type;
127 typedef Tpetra::Import<local_ordinal_type, global_ordinal_type> import_type;
128 typedef Tpetra::Export<local_ordinal_type, global_ordinal_type> export_type;
129 typedef Tpetra::CrsGraph<local_ordinal_type, global_ordinal_type> graph_type;
130 typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type> matrix_type;
131
132 template <typename LocalOrdinal, typename GlobalOrdinal>
133 class SimpleTieBreak : public Tpetra::Details::TieBreak<LocalOrdinal, GlobalOrdinal>
134 {
135 std::size_t
136 selectedIndex(GlobalOrdinal GID, const std::vector<std::pair<int, LocalOrdinal>>& pid_and_lid) const
137 {
138 std::size_t selected_index = 0;
139 int selected_pid = pid_and_lid[0].first;
140 for (unsigned int i = 0; i < pid_and_lid.size(); i++) {
141 int pid = pid_and_lid[i].first;
142 if (pid < selected_pid) {
143 selected_index = i;
144 selected_pid = pid;
145 }
146 }
147 return selected_index;
148 }
149 };
150#endif
151
153
154 void
155 Initialize(GenesisMesh const& mesh, std::vector<int> const& global_node_ids, comm_type comm);
156
157 void
158 Initialize(int d, unsigned int n, comm_type comm, std::vector<int> const& global_node_ids);
159
160 void
162
163 int
165
166 void
168
169 void
170 TangentStiffnessMatrixReplaceValue(int row, int col, double value);
171
172#ifdef NIMBLE_HAVE_TRILINOS
174 GetTpetraMatrixContainer()
175 {
176 return crs_matrix_container_;
177 }
178#endif
179
180 void
181 VectorReduction(ModelData& model_data, std::string quantity_label);
182
183 void
184 VectorReduction(int data_dimension, double* data);
185
186 int dim_;
187 std::vector<int> global_node_ids_;
188
189#ifdef NIMBLE_HAVE_TRILINOS
190 comm_type comm_;
191 Teuchos::RCP<vector_type> vec_1d_;
192 Teuchos::RCP<vector_type> vec_1d_one_to_one_;
193 Teuchos::RCP<vector_type> vec_3d_;
194 Teuchos::RCP<vector_type> vec_3d_one_to_one_;
195 Teuchos::RCP<export_type> export_into_vec_1d_one_to_one_;
196 Teuchos::RCP<import_type> import_from_vec_1d_one_to_one_;
197 Teuchos::RCP<export_type> export_into_vec_3d_one_to_one_;
198 Teuchos::RCP<import_type> import_from_vec_3d_one_to_one_;
199 Teuchos::RCP<matrix_type> crs_matrix_;
201#endif
202};
203
204} // namespace nimble
205
206#endif
Definition nimble_genesis_mesh.h:59
Definition nimble_model_data.h:67
int dim_
Definition nimble_tpetra_utils.h:186
void TangentStiffnessMatrixReplaceValue(int row, int col, double value)
Definition nimble_tpetra_utils.cc:208
std::vector< int > global_node_ids_
Definition nimble_tpetra_utils.h:187
void Initialize(GenesisMesh const &mesh, std::vector< int > const &global_node_ids, comm_type comm)
Definition nimble_tpetra_utils.cc:55
void VectorReduction(ModelData &model_data, std::string quantity_label)
Definition nimble_tpetra_utils.cc:231
void TangentStiffnessMatrixSetScalar(double value)
Definition nimble_tpetra_utils.cc:200
int TangentStiffnessMatrixNumNonzeros()
Definition nimble_tpetra_utils.cc:190
void AllocateTangentStiffnessMatrix(GenesisMesh const &mesh)
Definition nimble_tpetra_utils.cc:110
TpetraContainer()
Definition nimble_tpetra_utils.h:152
Definition nimble_tpetra_utils.h:80
Definition kokkos_contact_manager.h:49
int comm_type
Definition nimble_tpetra_utils.h:75
#define NIMBLE_ABORT(...)
Definition nimble_macros.h:87
@ Scalar
Definition nimble_view.h:55