NimbleSM
NimbleSM is a solid mechanics simulation code for dynamic systems
Loading...
Searching...
No Matches
nimble_model_data_base.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_BASE_H
45#define NIMBLE_MODEL_DATA_BASE_H
46
47#include <map>
48#include <sstream>
49#include <string>
50#include <vector>
51
52#include "nimble_block.h"
53#include "nimble_data_utils.h"
55#include "nimble_genesis_mesh.h"
57#include "nimble_macros.h"
58#include "nimble_view.h"
59
60namespace nimble {
61
62class DataManager;
64
66{
68 int stress = -1;
70
72 int displacement = -1;
73 int velocity = -1;
74 int acceleration = -1;
75
76 int lumped_mass = -1;
78 int contact_force = -1;
80
81 int state_scalar = -1;
82 int state_vec3D = -1;
85};
86
88{
89 public:
90 /// \brief Constructor
91 ModelDataBase() = default;
92
93 /// \brief Destructor
94 virtual ~ModelDataBase() = default;
95
96 //--- Virtual functions
97
98 /// \brief Allocate data storage for a node-based quantity
99 ///
100 /// \param length
101 /// \param label
102 /// \param num_objects
103 /// \return Field ID for the data allocated
104 virtual int
105 AllocateNodeData(Length length, std::string label, int num_objects) = 0;
106
107 int
108 GetFieldIdChecked(const std::string& field_label) const
109 {
110 int id = GetFieldId(field_label);
111 if (id < 0) {
112 std::ostringstream errc;
113 errc << "Field \"" << field_label << "\" not allocated";
114 NIMBLE_ABORT(errc.str());
115 }
116 return id;
117 }
118
119 /// \brief Returns the field ID for a specific label
120 ///
121 /// \param field_label Label for a stored quantity
122 /// \return Field ID to identify the data storage
123 virtual int
124 GetFieldId(const std::string& field_label) const = 0;
125
126 /// \brief Initialize the different blocks in the mesh
127 ///
128 /// \param data_manager Reference to the data manager
129 /// \param material_factory_base Shared pointer to the material factory
130 virtual void
132 nimble::DataManager& data_manager,
133 const std::shared_ptr<nimble::MaterialFactoryBase>& material_factory_base) = 0;
134
135 /// \brief Copy time state (n+1) into time state (n)
136 ///
137 /// \param data_manager Reference to the data manager
138 virtual void
139 UpdateStates(const nimble::DataManager& data_manager) = 0;
140
141 /// \brief Get view of scalar quantity defined on nodes
142 ///
143 /// \param label the data label
144 /// \return Viewify<1> object for scalar quantity
146 GetScalarNodeData(const std::string& label)
147 {
149 };
150
151 /// \brief Get view of scalar quantity defined on nodes
152 ///
153 /// \param field_id the field id (see DataManager::GetFieldIDs())
154 /// \return Viewify<1> object for scalar quantity
155 virtual nimble::Viewify<1>
156 GetScalarNodeData(int field_id) = 0;
157
158 /// \brief Get view of vector quantity defined on nodes
159 ///
160 /// \param label the data label
161 /// \return Viewify<2> object for vector quantity
163 GetVectorNodeData(const std::string& label)
164 {
166 }
167
168 /// \brief Get view of scalar quantity defined on nodes
169 ///
170 /// \param field_id the field id (see DataManager::GetFieldIDs())
171 /// \return Viewify<2> object for vector quantity
172 virtual nimble::Viewify<2>
173 GetVectorNodeData(int field_id) = 0;
174
175 /// \brief Compute the lumped mass
176 ///
177 /// \param data_manager Reference to the data manager
178 virtual void
180
181 virtual void
183 {
184 NIMBLE_ABORT(" Exodus Output Not Implemented \n");
185 }
186
187 /// \brief Write output of simulation in Exodus format
188 ///
189 /// \param[in] data_manager Reference to data manager
190 /// \param[in] time_current Time value
191 virtual void
192 WriteExodusOutput(nimble::DataManager& data_manager, double time_current)
193 {
194 NIMBLE_ABORT(" Exodus Output Not Implemented \n");
195 }
196
197 /// \brief Compute the external force
198 ///
199 /// \param data_manager Reference to the DataManager object
200 /// \param time_previous
201 /// \param time_current
202 /// \param is_output_step
203 ///
204 /// \note This routine is a placeholder.
205 virtual void
207 nimble::DataManager& data_manager,
208 double time_previous,
209 double time_current,
210 bool is_output_step){};
211
212 /// \brief Compute the internal force
213 ///
214 /// \param[in] data_manager
215 /// \param[in] time_previous
216 /// \param[in] time_current
217 /// \param[in] is_output_step
218 /// \param[in] displacement
219 /// \param[out] internal_force Output for internal force
220 virtual void
222 nimble::DataManager& data_manager,
223 double time_previous,
224 double time_current,
225 bool is_output_step,
226 const nimble::Viewify<2>& displacement,
227 nimble::Viewify<2>& force){};
228
229 /// \brief Apply initial conditions
230 virtual void
232
233 /// \brief Apply kinematic conditions
234 virtual void
235 ApplyKinematicConditions(nimble::DataManager& data_manager, double time_current, double time_previous);
236
237 /// \brief Update model with new velocity
238 ///
239 /// \param[in] data_manager Reference to the data manager
240 /// \param[in] dt Current time step
241 ///
242 /// \note This routine is usually empty.
243 /// The UQ model data is one case using this routine.
244 virtual void
246 {
247 }
248
249 /// \brief Update model with new displacement
250 ///
251 /// \param[in] data_manager Reference to the data manager
252 /// \param[in] dt Current time step
253 ///
254 /// \note This routine is usually empty.
255 /// The UQ model data is one case using this routine.
256 virtual void
258 {
259 }
260
261 //--- Common interface routines
262
263 /// \brief Get the spatial dimension
264 ///
265 /// \return Spatial dimension
266 int
268 {
269 return dim_;
270 }
271
272 /// \brief Set the critical time step
273 ///
274 /// \param time_step Critical time step to use.
275 void
276 SetCriticalTimeStep(double time_step)
277 {
278 critical_time_step_ = time_step;
279 }
280
281 /// \brief Set spatial dimension
282 ///
283 /// \param dim Spatial dimension
284 void
285 SetDimension(int dim);
286
287 /// \brief Set reference coordinates
288 ///
289 /// \param mesh Mesh
290 void
292
293 /// \brief Get the critical time step
294 ///
295 /// \return Time step
296 double
298 {
299 return critical_time_step_;
300 }
301
302 const std::vector<std::string>&
307
308 const std::map<int, std::vector<std::string>>&
310 {
312 }
313
314 const std::map<int, std::vector<std::string>>&
319
320 const std::map<int, std::vector<std::string>>&
325
326 protected:
327 //! Problem dimension, either 2 or 3.
328 int dim_ = 3;
329
330 //! Critical time step
332
333 //! Output labels for node data that will be written to disk
334 std::vector<std::string> output_node_component_labels_;
335
336 //! Map key is the block_id, vector contains component-wise label for each
337 //! scalar entry in the data array.
338 std::map<int, std::vector<std::string>> element_component_labels_;
339
340 //! Output labels for element data that will be written to disk.
341 std::map<int, std::vector<std::string>> output_element_component_labels_;
342
343 //! Output labels for derived element data that will be written to disk.
344 std::map<int, std::vector<std::string>> derived_output_element_data_labels_;
345};
346
347} // namespace nimble
348
349#endif
Definition nimble_data_manager.h:70
Definition nimble_genesis_mesh.h:59
Definition nimble_material_factory_base.h:61
int dim_
Problem dimension, either 2 or 3.
Definition nimble_model_data_base.h:328
virtual void ComputeLumpedMass(nimble::DataManager &data_manager)=0
Compute the lumped mass.
void SetReferenceCoordinates(const nimble::GenesisMesh &mesh)
Set reference coordinates.
Definition nimble_model_data_base.cc:59
virtual ~ModelDataBase()=default
Destructor.
void SetCriticalTimeStep(double time_step)
Set the critical time step.
Definition nimble_model_data_base.h:276
virtual void InitializeExodusOutput(nimble::DataManager &data_manager)
Definition nimble_model_data_base.h:182
void SetDimension(int dim)
Set spatial dimension.
Definition nimble_model_data_base.cc:52
nimble::Viewify< 2 > GetVectorNodeData(const std::string &label)
Get view of vector quantity defined on nodes.
Definition nimble_model_data_base.h:163
virtual void ApplyKinematicConditions(nimble::DataManager &data_manager, double time_current, double time_previous)
Apply kinematic conditions.
Definition nimble_model_data_base.cc:93
const std::map< int, std::vector< std::string > > & GetElementDataLabelsForOutput() const
Definition nimble_model_data_base.h:315
virtual void ApplyInitialConditions(nimble::DataManager &data_manager)
Apply initial conditions.
Definition nimble_model_data_base.cc:84
virtual void InitializeBlocks(nimble::DataManager &data_manager, const std::shared_ptr< nimble::MaterialFactoryBase > &material_factory_base)=0
Initialize the different blocks in the mesh.
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
int GetDimension() const
Get the spatial dimension.
Definition nimble_model_data_base.h:267
virtual void UpdateWithNewVelocity(nimble::DataManager &data_manager, double dt)
Update model with new velocity.
Definition nimble_model_data_base.h:245
virtual 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)
Compute the internal force.
Definition nimble_model_data_base.h:221
virtual nimble::Viewify< 2 > GetVectorNodeData(int field_id)=0
Get view of scalar quantity defined on nodes.
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
virtual int GetFieldId(const std::string &field_label) const =0
Returns the field ID for a specific label.
virtual void WriteExodusOutput(nimble::DataManager &data_manager, double time_current)
Write output of simulation in Exodus format.
Definition nimble_model_data_base.h:192
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
virtual nimble::Viewify< 1 > GetScalarNodeData(int field_id)=0
Get view of scalar quantity defined on nodes.
double GetCriticalTimeStep() const
Get the critical time step.
Definition nimble_model_data_base.h:297
double critical_time_step_
Critical time step.
Definition nimble_model_data_base.h:331
virtual void UpdateWithNewDisplacement(nimble::DataManager &data_manager, double dt)
Update model with new displacement.
Definition nimble_model_data_base.h:257
const std::map< int, std::vector< std::string > > & GetElementDataLabels() const
Definition nimble_model_data_base.h:309
std::map< int, std::vector< std::string > > element_component_labels_
Definition nimble_model_data_base.h:338
virtual void UpdateStates(const nimble::DataManager &data_manager)=0
Copy time state (n+1) into time state (n)
const std::map< int, std::vector< std::string > > & GetDerivedElementDataLabelsForOutput() const
Definition nimble_model_data_base.h:321
virtual int AllocateNodeData(Length length, std::string label, int num_objects)=0
Allocate data storage for a node-based quantity.
int GetFieldIdChecked(const std::string &field_label) const
Definition nimble_model_data_base.h:108
virtual void ComputeExternalForce(nimble::DataManager &data_manager, double time_previous, double time_current, bool is_output_step)
Compute the external force.
Definition nimble_model_data_base.h:206
const std::vector< std::string > & GetNodeDataLabelsForOutput() const
Definition nimble_model_data_base.h:303
Definition nimble_view.h:72
Definition kokkos_contact_manager.h:49
Length
Definition nimble_data_utils.h:66
#define NIMBLE_ABORT(...)
Definition nimble_macros.h:87
Definition nimble_model_data_base.h:66
int velocity
Definition nimble_model_data_base.h:73
int acceleration
Definition nimble_model_data_base.h:74
int deformation_gradient
Definition nimble_model_data_base.h:67
int stress
Definition nimble_model_data_base.h:68
int lumped_mass
Definition nimble_model_data_base.h:76
int reference_coordinates
Definition nimble_model_data_base.h:71
int state_sym_tensor
Definition nimble_model_data_base.h:83
int contact_force
Definition nimble_model_data_base.h:78
int displacement
Definition nimble_model_data_base.h:72
int unrotated_stress
Definition nimble_model_data_base.h:69
int external_force
Definition nimble_model_data_base.h:79
int state_full_tensor
Definition nimble_model_data_base.h:84
int state_scalar
Definition nimble_model_data_base.h:81
int internal_force
Definition nimble_model_data_base.h:77
int state_vec3D
Definition nimble_model_data_base.h:82