NimbleSM
NimbleSM is a solid mechanics simulation code for dynamic systems
Loading...
Searching...
No Matches
nimble_genesis_mesh.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_GENESIS_MESH_H
45#define NIMBLE_GENESIS_MESH_H
46
47#ifdef NIMBLE_HAVE_DARMA
48#include "darma.h"
49#else
50#include <map>
51#include <vector>
52#endif
53
54#include <string>
55
56namespace nimble {
57
59{
60 public:
61 GenesisMesh() : file_name_("undefined"), dim_(-1) {}
62
63 ~GenesisMesh() = default;
64
65#ifdef NIMBLE_HAVE_DARMA
66 template <typename ArchiveType>
67 void
68 serialize(ArchiveType& ar)
69 {
73 }
74#endif
75
76 bool
77 IsValid() const
78 {
79 if (file_name_ == "none") { return false; }
80 return true;
81 }
82
83 std::string
84 FileName() const
85 {
86 return file_name_;
87 }
88
89 unsigned int
91 {
92 return node_x_.size();
93 }
94
95 const int*
97 {
98 return &node_global_id_[0];
99 }
100 std::size_t
102 {
103 return node_global_id_.size();
104 }
105
106 int
108 {
109 int max_id = -1;
110 for (auto id : node_global_id_) {
111 if (id > max_id) { max_id = id; }
112 }
113 return max_id;
114 }
115
116 unsigned int
118 {
119 return elem_global_id_.size();
120 }
121
122 const int*
124 {
125 return &elem_global_id_[0];
126 }
127
128 std::vector<int> const&
129 GetElementGlobalIdsInBlock(int block_id) const
130 {
131 return block_elem_global_ids_.at(block_id);
132 }
133
134 unsigned int
136 {
137 return block_ids_.size();
138 }
139
140 unsigned int
142 {
143 return all_block_ids_.size();
144 }
145
146 bool
147 HasBlock(std::string const& block_name) const;
148
149 std::vector<int>
151 {
152 return block_ids_;
153 }
154
155 std::vector<int>
157 {
158 return all_block_ids_;
159 }
160
161 int
162 GetNumElementsInBlock(int block_id) const;
163
164 std::map<int, int>
165 GetNumElementsInBlock() const;
166
167 int
168 GetNumNodesPerElement(int block_id) const
169 {
170 return block_num_nodes_per_elem_.at(block_id);
171 }
172
173 std::map<int, int>
175 {
177 }
178
179 std::string
180 GetElementType(int block_id) const;
181
182 std::string
183 GetBlockName(int block_id) const
184 {
185 return all_block_names_.at(block_id);
186 }
187
188 int
189 GetBlockId(std::string const& block_name) const;
190
191 void
192 BlockNamesToOnProcessorBlockIds(std::vector<std::string> const& block_names, std::vector<int>& block_ids);
193
194 int
195 GetDim() const
196 {
197 return dim_;
198 }
199
200 const double*
202 {
203 return &node_x_[0];
204 }
205
206 const double*
208 {
209 return &node_y_[0];
210 }
211
212 const double*
214 {
215 return &node_z_[0];
216 }
217
218 const int*
219 GetConnectivity(int block_id) const
220 {
221 return &block_elem_connectivity_.at(block_id)[0];
222 }
223
224 std::map<int, std::vector<int>>&
226 {
228 }
229
230 int
232 {
233 return static_cast<int>(node_set_ids_.size());
234 }
235
236 std::vector<int>
238 {
239 return node_set_ids_;
240 }
241
242 std::map<int, std::string>
244 {
245 return node_set_names_;
246 }
247
248 std::map<int, std::vector<int>>
250 {
251 return node_sets_;
252 }
253
254 std::map<int, std::vector<double>>
259
260 int
262 {
263 return static_cast<int>(side_set_ids_.size());
264 }
265
266 std::vector<int>
268 {
269 return side_set_ids_;
270 }
271
272 std::map<int, std::string>
274 {
275 return side_set_names_;
276 }
277
278 std::map<int, std::vector<int>>
280 {
281 return side_sets_;
282 }
283
284 std::map<int, std::vector<double>>
289
290 void
291 BoundingBox(double& x_min, double& x_max, double& y_min, double& y_max, double& z_min, double& z_max) const;
292
293 std::vector<double>
294 BoundingBoxCenter() const;
295
296 void
298 int local_primary_node_id,
299 int local_secondary_node_id,
300 const int* global_node_ids,
301 std::map<int, int>& global_node_id_secondary_to_primary) const;
302
303 void
304 Print(bool verbose = false, int my_rank = 0) const;
305
306 void
307 ReadFile(std::string file_name);
308
309 void
310 ReadTextFile(std::string file_name);
311
312 //! Create a genesis mesh object using existing data (intended for contact
313 //! visualization).
314 void
316 std::string const& file_name,
317 std::vector<int> const& node_global_id,
318 std::vector<double> const& node_x,
319 std::vector<double> const& node_y,
320 std::vector<double> const& node_z,
321 std::vector<int> const& elem_global_id,
322 std::vector<int> const& block_ids,
323 std::map<int, std::string> const& block_names,
324 std::map<int, std::vector<int>> const& block_elem_global_ids,
325 std::map<int, int> const& block_num_nodes_per_elem,
326 std::map<int, std::vector<int>> const& block_elem_connectivity);
327
328 protected:
329 void
330 ReportExodusError(int error_code, const char* method_name, const char* exodus_method_name) const;
331
332 std::string file_name_;
333 int dim_;
334
335 std::vector<int> node_global_id_;
336 std::vector<double> node_x_;
337 std::vector<double> node_y_;
338 std::vector<double> node_z_;
339 std::vector<int> elem_global_id_;
340 std::vector<int> all_block_ids_;
341 std::vector<int> block_ids_;
342 std::map<int, std::string> all_block_names_;
343 std::map<int, std::string> block_names_;
344 std::map<int, std::vector<int>> block_elem_global_ids_;
345 std::map<int, int> block_num_nodes_per_elem_;
346 std::map<int, std::vector<int>> block_elem_connectivity_;
347 std::vector<int> node_set_ids_;
348 std::map<int, std::string> node_set_names_;
349 std::map<int, std::vector<int>> node_sets_;
350 std::map<int, std::vector<double>> ns_distribution_factors_;
351 std::vector<int> side_set_ids_;
352 std::map<int, std::string> side_set_names_;
353 std::map<int, std::vector<int>> side_sets_;
354 std::map<int, std::vector<double>> ss_distribution_factors_;
355};
356
357} // namespace nimble
358
359#endif // NIMBLE_INPUT_EXODUS_H
std::map< int, std::string > node_set_names_
Definition nimble_genesis_mesh.h:348
void BoundingBox(double &x_min, double &x_max, double &y_min, double &y_max, double &z_min, double &z_max) const
Definition nimble_genesis_mesh.cc:537
std::vector< int > GetBlockIds() const
Definition nimble_genesis_mesh.h:150
std::map< int, std::vector< int > > GetNodeSets() const
Definition nimble_genesis_mesh.h:249
std::vector< int > GetAllBlockIds() const
Definition nimble_genesis_mesh.h:156
~GenesisMesh()=default
std::string GetElementType(int block_id) const
Definition nimble_genesis_mesh.cc:480
const int * GetNodeGlobalIds() const
Definition nimble_genesis_mesh.h:96
std::map< int, std::vector< double > > ns_distribution_factors_
Definition nimble_genesis_mesh.h:350
std::string FileName() const
Definition nimble_genesis_mesh.h:84
const int * GetElementGlobalIds() const
Definition nimble_genesis_mesh.h:123
void Initialize(std::string const &file_name, std::vector< int > const &node_global_id, std::vector< double > const &node_x, std::vector< double > const &node_y, std::vector< double > const &node_z, std::vector< int > const &elem_global_id, std::vector< int > const &block_ids, std::map< int, std::string > const &block_names, std::map< int, std::vector< int > > const &block_elem_global_ids, std::map< int, int > const &block_num_nodes_per_elem, std::map< int, std::vector< int > > const &block_elem_connectivity)
Definition nimble_genesis_mesh.cc:430
std::vector< int > all_block_ids_
Definition nimble_genesis_mesh.h:340
std::vector< int > side_set_ids_
Definition nimble_genesis_mesh.h:351
GenesisMesh()
Definition nimble_genesis_mesh.h:61
std::map< int, std::vector< int > > block_elem_global_ids_
Definition nimble_genesis_mesh.h:344
std::map< int, std::vector< int > > node_sets_
Definition nimble_genesis_mesh.h:349
std::vector< int > const & GetElementGlobalIdsInBlock(int block_id) const
Definition nimble_genesis_mesh.h:129
const double * GetCoordinatesX() const
Definition nimble_genesis_mesh.h:201
unsigned int GetNumElements() const
Definition nimble_genesis_mesh.h:117
void Print(bool verbose=false, int my_rank=0) const
Definition nimble_genesis_mesh.cc:587
const int * GetConnectivity(int block_id) const
Definition nimble_genesis_mesh.h:219
std::map< int, std::string > side_set_names_
Definition nimble_genesis_mesh.h:352
std::map< int, std::vector< int > > block_elem_connectivity_
Definition nimble_genesis_mesh.h:346
void BlockNamesToOnProcessorBlockIds(std::vector< std::string > const &block_names, std::vector< int > &block_ids)
Definition nimble_genesis_mesh.cc:526
const double * GetCoordinatesY() const
Definition nimble_genesis_mesh.h:207
std::map< int, int > GetNumNodesPerElement() const
Definition nimble_genesis_mesh.h:174
std::map< int, std::string > GetSideSetNames() const
Definition nimble_genesis_mesh.h:273
std::size_t GetNumNodeGlobalIds() const
Definition nimble_genesis_mesh.h:101
unsigned int GetNumBlocks() const
Definition nimble_genesis_mesh.h:135
bool IsValid() const
Definition nimble_genesis_mesh.h:77
unsigned int GetNumGlobalBlocks() const
Definition nimble_genesis_mesh.h:141
std::vector< double > BoundingBoxCenter() const
Definition nimble_genesis_mesh.cc:563
int GetNumNodeSets() const
Definition nimble_genesis_mesh.h:231
unsigned int GetNumNodes() const
Definition nimble_genesis_mesh.h:90
std::vector< int > node_set_ids_
Definition nimble_genesis_mesh.h:347
std::string file_name_
Definition nimble_genesis_mesh.h:332
std::map< int, std::vector< int > > & GetConnectivity()
Definition nimble_genesis_mesh.h:225
std::map< int, std::vector< int > > side_sets_
Definition nimble_genesis_mesh.h:353
int dim_
Definition nimble_genesis_mesh.h:333
std::map< int, std::vector< double > > GetNodeSetDistributionFactors() const
Definition nimble_genesis_mesh.h:255
void AppendPeriodicPair(int local_primary_node_id, int local_secondary_node_id, const int *global_node_ids, std::map< int, int > &global_node_id_secondary_to_primary) const
Definition nimble_genesis_mesh.cc:575
std::map< int, std::vector< double > > GetSideSetDistributionFactors() const
Definition nimble_genesis_mesh.h:285
std::map< int, std::string > GetNodeSetNames() const
Definition nimble_genesis_mesh.h:243
std::map< int, std::string > all_block_names_
Definition nimble_genesis_mesh.h:342
std::map< int, std::vector< double > > ss_distribution_factors_
Definition nimble_genesis_mesh.h:354
std::vector< int > GetNodeSetIds() const
Definition nimble_genesis_mesh.h:237
std::vector< double > node_x_
Definition nimble_genesis_mesh.h:336
std::map< int, int > GetNumElementsInBlock() const
Definition nimble_genesis_mesh.cc:470
bool HasBlock(std::string const &block_name) const
Definition nimble_genesis_mesh.cc:508
std::vector< int > node_global_id_
Definition nimble_genesis_mesh.h:335
std::vector< double > node_z_
Definition nimble_genesis_mesh.h:338
int GetNumNodesPerElement(int block_id) const
Definition nimble_genesis_mesh.h:168
void ReadFile(std::string file_name)
Definition nimble_genesis_mesh.cc:63
const double * GetCoordinatesZ() const
Definition nimble_genesis_mesh.h:213
int GetBlockId(std::string const &block_name) const
Definition nimble_genesis_mesh.cc:517
void ReportExodusError(int error_code, const char *method_name, const char *exodus_method_name) const
Definition nimble_genesis_mesh.cc:614
int GetMaxNodeGlobalId() const
Definition nimble_genesis_mesh.h:107
std::string GetBlockName(int block_id) const
Definition nimble_genesis_mesh.h:183
void ReadTextFile(std::string file_name)
Definition nimble_genesis_mesh.cc:319
std::map< int, std::string > block_names_
Definition nimble_genesis_mesh.h:343
std::vector< int > elem_global_id_
Definition nimble_genesis_mesh.h:339
std::vector< int > GetSideSetIds() const
Definition nimble_genesis_mesh.h:267
std::vector< double > node_y_
Definition nimble_genesis_mesh.h:337
int GetDim() const
Definition nimble_genesis_mesh.h:195
std::map< int, std::vector< int > > GetSideSets() const
Definition nimble_genesis_mesh.h:279
std::vector< int > block_ids_
Definition nimble_genesis_mesh.h:341
int GetNumSideSets() const
Definition nimble_genesis_mesh.h:261
std::map< int, int > block_num_nodes_per_elem_
Definition nimble_genesis_mesh.h:345
Definition kokkos_contact_manager.h:49