NimbleSM
NimbleSM is a solid mechanics simulation code for dynamic systems
Loading...
Searching...
No Matches
nimble_model_data.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_MODEL_DATA_H
45#define NIMBLE_MODEL_DATA_H
46
47#include "nimble_block.h"
48#include "nimble_defs.h"
50#include "nimble_view.h"
51
52#ifdef NIMBLE_HAVE_DARMA
53#include "darma.h"
54#else
55#include <map>
56#include <string>
57#include <vector>
58#endif
59
60namespace nimble {
61
62class DataManager;
65
67{
68 public:
69 ModelData() = default;
70
71 ~ModelData() override = default;
72
73 //--- Common interface from base class
74
75 /// \brief Allocate data storage for a node-based quantity
76 ///
77 /// \param length
78 /// \param label
79 /// \param num_objects
80 /// \return Field ID for the data allocated
81 int
82 AllocateNodeData(Length length, std::string label, int num_objects) override;
83
84 /// \brief Returns the field ID for a specific label
85 ///
86 /// \param field_label Label for a stored quantity
87 /// \return Field ID to identify the data storage
88 int
89 GetFieldId(const std::string& label) const override;
90
91 /// \brief Initialize the different blocks in the mesh
92 ///
93 /// \param data_manager Reference to the data manager
94 /// \param material_factory_base Shared pointer to the material factory
95 void
97 nimble::DataManager& data_manager,
98 const std::shared_ptr<nimble::MaterialFactoryBase>& material_factory_base) override;
99
100 /// \brief Copy time state (n+1) into time state (n)
101 ///
102 /// \param data_manager Reference to the data manager
103 void
104 UpdateStates(const nimble::DataManager& data_manager) override
105 {
107 }
108
111
112 /// \brief Get view of scalar quantity defined on nodes
113 ///
114 /// \param field_id the field id (see DataManager::GetFieldIDs())
115 /// \return Viewify<1> object for scalar quantity
117 GetScalarNodeData(int field_id) override;
118
119 /// \brief Get view of vector quantity defined on nodes
120 ///
121 /// \param field_id the field id (see DataManager::GetFieldIDs())
122 /// \return Viewify<2> object for vector quantity
124 GetVectorNodeData(int field_id) override;
125
126 void
127 ComputeLumpedMass(nimble::DataManager& data_manager) override;
128
129 void
130 InitializeExodusOutput(nimble::DataManager& data_manager) override;
131
132 void
133 WriteExodusOutput(nimble::DataManager& data_manager, double time_current) override;
134
135 /// \brief Compute the external force
136 ///
137 /// \param data_manager Reference to the DataManager
138 /// \param time_previous
139 /// \param time_current
140 /// \param is_output_step
141 void
143 nimble::DataManager& data_manager,
144 double time_previous,
145 double time_current,
146 bool is_output_step) override;
147
148 /// \brief Compute the internal force
149 ///
150 /// \param[in] data_manager
151 /// \param[in] time_previous
152 /// \param[in] time_current
153 /// \param[in] is_output_step
154 /// \param[in] displacement
155 /// \param[out] internal_force Output for internal force
156 void
158 nimble::DataManager& data_manager,
159 double time_previous,
160 double time_current,
161 bool is_output_step,
162 const nimble::Viewify<2>& displacement,
163 nimble::Viewify<2>& force) override;
164
165 //--- Specific routines
166
167#ifdef NIMBLE_HAVE_DARMA
168 template <typename ArchiveType>
169 void
170 serialize(ArchiveType& ar)
171 {
176 }
177#endif
178
179 Field
180 GetField(int field_id);
181
182 double*
183 GetNodeData(int field_id);
184
185 void
186 GetNodeDataForOutput(std::vector<std::vector<double>>& single_component_arrays);
187
188 void
189 DeclareElementData(int block_id, std::vector<std::pair<std::string, Length>> const& data_labels_and_lengths);
190
191 void
192 AllocateElementData(std::map<int, int> const& num_integration_points_in_each_block);
193
194 std::vector<double>&
195 GetElementDataOld(int block_id)
196 {
197 return element_data_n_.at(block_id);
198 }
199
200 std::vector<double>&
201 GetElementDataNew(int block_id)
202 {
203 return element_data_np1_.at(block_id);
204 }
205
206 void
207 GetElementDataForOutput(std::map<int, std::vector<std::vector<double>>>& single_component_arrays);
208
209 void
210 SpecifyOutputFields(const std::string& output_field_string);
211
212 std::map<int, std::shared_ptr<nimble::Block>>&
214 {
215 return blocks_;
216 }
217
218 std::map<int, std::shared_ptr<nimble::Block>> const&
219 GetBlocks() const
220 {
221 return blocks_;
222 }
223
224 std::vector<int>&
229
230 std::map<int, int>&
235
236 protected:
237 void
238 AssignFieldId(Field& field);
239
240 void
241 GetNodeDataComponent(int field_id, int component, double* const component_data);
242
243 double*
244 GetNodeData(const std::string& label);
245
246 template <typename TBlock>
247 void
249 nimble::DataManager& data_manager,
250 const std::shared_ptr<nimble::MaterialFactoryBase>& material_factory_base);
251
252 void
254 nimble::DataManager& data_manager,
255 const std::shared_ptr<nimble::MaterialFactoryBase>& material_factory_base);
256
257 protected:
258 //! Block ids
259 std::vector<int> block_ids_;
260
261 //! Blocks
262 std::map<int, std::shared_ptr<nimble::Block>> blocks_;
263
264 //! Map key is the field_id, value is the corresponding Field.
265 std::map<int, Field> data_fields_;
266
267 //! Map key is the field_id, vector contains the nested data array for the
268 //! given nodal field.
269 std::map<int, std::vector<double>> node_data_;
270
271 //! Map key is the block_id, the vector contains the field ids for the fields
272 //! on that block.
273 std::map<int, std::vector<int>> element_data_fields_;
274
275 //! Map key is the block_id, vector contains full data array for that block at
276 //! step N.
277 std::map<int, std::vector<double>> element_data_n_;
278
279 //! Map key is the block_id, vector contains full data array for that block at
280 //! step N+1.
281 std::map<int, std::vector<double>> element_data_np1_;
282
283 //! List of node ids that are shared across multiple ranks
284 std::vector<int> globally_shared_nodes_;
285
286 //! Map from global node it to local node id
288
289 //! Information for Exodus output about node data
290 std::vector<std::vector<double>> node_data_for_output_;
291
292 //! Information for Exodus output about element data
293 std::map<int, std::vector<std::vector<double>>> elem_data_for_output_;
294
295 //! Information for Exodus output about element data
296 std::map<int, std::vector<std::vector<double>>> derived_elem_data_;
297};
298
299} // namespace nimble
300
301#endif
Definition nimble_data_manager.h:70
Definition nimble_data_utils.h:124
Definition nimble_material_factory_base.h:61
int dim_
Problem dimension, either 2 or 3.
Definition nimble_model_data_base.h:328
nimble::Viewify< 2 > GetVectorNodeData(const std::string &label)
Get view of vector quantity defined on nodes.
Definition nimble_model_data_base.h:163
ModelDataBase()=default
Constructor.
nimble::Viewify< 1 > GetScalarNodeData(const std::string &label)
Get view of scalar quantity defined on nodes.
Definition nimble_model_data_base.h:146
std::map< int, std::vector< std::string > > output_element_component_labels_
Output labels for element data that will be written to disk.
Definition nimble_model_data_base.h:341
std::vector< std::string > output_node_component_labels_
Output labels for node data that will be written to disk.
Definition nimble_model_data_base.h:334
std::map< int, std::vector< std::string > > derived_output_element_data_labels_
Output labels for derived element data that will be written to disk.
Definition nimble_model_data_base.h:344
double critical_time_step_
Critical time step.
Definition nimble_model_data_base.h:331
std::map< int, std::vector< std::string > > element_component_labels_
Definition nimble_model_data_base.h:338
std::map< int, std::shared_ptr< nimble::Block > > & GetBlocks()
Definition nimble_model_data.h:213
std::vector< double > & GetElementDataOld(int block_id)
Definition nimble_model_data.h:195
void SpecifyOutputFields(const std::string &output_field_string)
Definition nimble_model_data.cc:216
void WriteExodusOutput(nimble::DataManager &data_manager, double time_current) override
Write output of simulation in Exodus format.
Definition nimble_model_data.cc:558
std::map< int, std::vector< std::vector< double > > > derived_elem_data_
Information for Exodus output about element data.
Definition nimble_model_data.h:296
void ComputeInternalForce(nimble::DataManager &data_manager, double time_previous, double time_current, bool is_output_step, const nimble::Viewify< 2 > &displacement, nimble::Viewify< 2 > &force) override
Compute the internal force.
Definition nimble_model_data.cc:621
std::map< int, std::vector< double > > node_data_
Definition nimble_model_data.h:269
Field GetField(int field_id)
Definition nimble_model_data.cc:74
double * GetNodeData(int field_id)
Definition nimble_model_data.cc:94
nimble::Viewify< 1 > GetScalarNodeData(int field_id) override
Get view of scalar quantity defined on nodes.
Definition nimble_model_data.cc:533
void InitializeBlocks(nimble::DataManager &data_manager, const std::shared_ptr< nimble::MaterialFactoryBase > &material_factory_base) override
Initialize the different blocks in the mesh.
Definition nimble_model_data.cc:487
std::map< int, std::shared_ptr< nimble::Block > > const & GetBlocks() const
Definition nimble_model_data.h:219
std::vector< int > globally_shared_nodes_
List of node ids that are shared across multiple ranks.
Definition nimble_model_data.h:284
void GetElementDataForOutput(std::map< int, std::vector< std::vector< double > > > &single_component_arrays)
Definition nimble_model_data.cc:172
~ModelData() override=default
std::map< int, int > global_node_id_to_local_node_id_
Map from global node it to local node id.
Definition nimble_model_data.h:287
void GetNodeDataComponent(int field_id, int component, double *const component_data)
Definition nimble_model_data.cc:401
nimble::Viewify< 2 > GetVectorNodeData(int field_id) override
Get view of vector quantity defined on nodes.
Definition nimble_model_data.cc:541
void UpdateStates(const nimble::DataManager &data_manager) override
Copy time state (n+1) into time state (n)
Definition nimble_model_data.h:104
void ComputeLumpedMass(nimble::DataManager &data_manager) override
Compute the lumped mass.
Definition nimble_model_data.cc:496
std::map< int, std::vector< double > > element_data_n_
Definition nimble_model_data.h:277
std::map< int, Field > data_fields_
Map key is the field_id, value is the corresponding Field.
Definition nimble_model_data.h:265
void AllocateInitializeElementData(nimble::DataManager &data_manager, const std::shared_ptr< nimble::MaterialFactoryBase > &material_factory_base)
Definition nimble_model_data.cc:452
int AllocateNodeData(Length length, std::string label, int num_objects) override
Allocate data storage for a node-based quantity.
Definition nimble_model_data.cc:80
std::map< int, std::vector< std::vector< double > > > elem_data_for_output_
Information for Exodus output about element data.
Definition nimble_model_data.h:293
std::map< int, std::shared_ptr< nimble::Block > > blocks_
Blocks.
Definition nimble_model_data.h:262
ModelData()=default
std::vector< std::vector< double > > node_data_for_output_
Information for Exodus output about node data.
Definition nimble_model_data.h:290
void AllocateElementData(std::map< int, int > const &num_integration_points_in_each_block)
Definition nimble_model_data.cc:143
std::map< int, std::vector< int > > element_data_fields_
Definition nimble_model_data.h:273
std::vector< int > block_ids_
Block ids.
Definition nimble_model_data.h:259
std::vector< int > & GetGloballySharedNodes()
Definition nimble_model_data.h:225
void DeclareElementData(int block_id, std::vector< std::pair< std::string, Length > > const &data_labels_and_lengths)
Definition nimble_model_data.cc:126
void AssignFieldId(Field &field)
Definition nimble_model_data.cc:371
void GetNodeDataForOutput(std::vector< std::vector< double > > &single_component_arrays)
Definition nimble_model_data.cc:100
std::vector< double > & GetElementDataNew(int block_id)
Definition nimble_model_data.h:201
void ComputeExternalForce(nimble::DataManager &data_manager, double time_previous, double time_current, bool is_output_step) override
Compute the external force.
Definition nimble_model_data.cc:610
void InitializeExodusOutput(nimble::DataManager &data_manager) override
Definition nimble_model_data.cc:549
int GetFieldId(const std::string &label) const override
Returns the field ID for a specific label.
Definition nimble_model_data.cc:65
std::map< int, int > & GetGlobalNodeIdToLocalNodeIdMap()
Definition nimble_model_data.h:231
void EmplaceBlocks(nimble::DataManager &data_manager, const std::shared_ptr< nimble::MaterialFactoryBase > &material_factory_base)
Definition nimble_model_data.cc:418
std::map< int, std::vector< double > > element_data_np1_
Definition nimble_model_data.h:281
Definition nimble_vector_communicator.h:74
Definition nimble_view.h:72
Definition kokkos_contact_manager.h:49
Length
Definition nimble_data_utils.h:66