NimbleSM
NimbleSM is a solid mechanics simulation code for dynamic systems
Loading...
Searching...
No Matches
nimble::ModelData Class Reference

#include <nimble_model_data.h>

Inheritance diagram for nimble::ModelData:
nimble::ModelDataBase

Public Member Functions

 ModelData ()=default
 
 ~ModelData () override=default
 
int AllocateNodeData (Length length, std::string label, int num_objects) override
 Allocate data storage for a node-based quantity.
 
int GetFieldId (const std::string &label) const override
 Returns the field ID for a specific label.
 
void InitializeBlocks (nimble::DataManager &data_manager, const std::shared_ptr< nimble::MaterialFactoryBase > &material_factory_base) override
 Initialize the different blocks in the mesh.
 
void UpdateStates (const nimble::DataManager &data_manager) override
 Copy time state (n+1) into time state (n)
 
nimble::Viewify< 1 > GetScalarNodeData (int field_id) override
 Get view of scalar quantity defined on nodes.
 
nimble::Viewify< 2 > GetVectorNodeData (int field_id) override
 Get view of vector quantity defined on nodes.
 
void ComputeLumpedMass (nimble::DataManager &data_manager) override
 Compute the lumped mass.
 
void InitializeExodusOutput (nimble::DataManager &data_manager) override
 
void WriteExodusOutput (nimble::DataManager &data_manager, double time_current) override
 Write output of simulation in Exodus format.
 
void ComputeExternalForce (nimble::DataManager &data_manager, double time_previous, double time_current, bool is_output_step) override
 Compute the external force.
 
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.
 
Field GetField (int field_id)
 
double * GetNodeData (int field_id)
 
void GetNodeDataForOutput (std::vector< std::vector< double > > &single_component_arrays)
 
void DeclareElementData (int block_id, std::vector< std::pair< std::string, Length > > const &data_labels_and_lengths)
 
void AllocateElementData (std::map< int, int > const &num_integration_points_in_each_block)
 
std::vector< double > & GetElementDataOld (int block_id)
 
std::vector< double > & GetElementDataNew (int block_id)
 
void GetElementDataForOutput (std::map< int, std::vector< std::vector< double > > > &single_component_arrays)
 
void SpecifyOutputFields (const std::string &output_field_string)
 
std::map< int, std::shared_ptr< nimble::Block > > & GetBlocks ()
 
std::map< int, std::shared_ptr< nimble::Block > > const & GetBlocks () const
 
std::vector< int > & GetGloballySharedNodes ()
 
std::map< int, int > & GetGlobalNodeIdToLocalNodeIdMap ()
 
nimble::Viewify< 1 > GetScalarNodeData (const std::string &label)
 Get view of scalar quantity defined on nodes.
 
nimble::Viewify< 2 > GetVectorNodeData (const std::string &label)
 Get view of vector quantity defined on nodes.
 
- Public Member Functions inherited from nimble::ModelDataBase
 ModelDataBase ()=default
 Constructor.
 
virtual ~ModelDataBase ()=default
 Destructor.
 
int GetFieldIdChecked (const std::string &field_label) const
 
nimble::Viewify< 1 > GetScalarNodeData (const std::string &label)
 Get view of scalar quantity defined on nodes.
 
nimble::Viewify< 2 > GetVectorNodeData (const std::string &label)
 Get view of vector quantity defined on nodes.
 
virtual void ApplyInitialConditions (nimble::DataManager &data_manager)
 Apply initial conditions.
 
virtual void ApplyKinematicConditions (nimble::DataManager &data_manager, double time_current, double time_previous)
 Apply kinematic conditions.
 
virtual void UpdateWithNewVelocity (nimble::DataManager &data_manager, double dt)
 Update model with new velocity.
 
virtual void UpdateWithNewDisplacement (nimble::DataManager &data_manager, double dt)
 Update model with new displacement.
 
int GetDimension () const
 Get the spatial dimension.
 
void SetCriticalTimeStep (double time_step)
 Set the critical time step.
 
void SetDimension (int dim)
 Set spatial dimension.
 
void SetReferenceCoordinates (const nimble::GenesisMesh &mesh)
 Set reference coordinates.
 
double GetCriticalTimeStep () const
 Get the critical time step.
 
const std::vector< std::string > & GetNodeDataLabelsForOutput () const
 
const std::map< int, std::vector< std::string > > & GetElementDataLabels () const
 
const std::map< int, std::vector< std::string > > & GetElementDataLabelsForOutput () const
 
const std::map< int, std::vector< std::string > > & GetDerivedElementDataLabelsForOutput () const
 

Protected Member Functions

void AssignFieldId (Field &field)
 
void GetNodeDataComponent (int field_id, int component, double *const component_data)
 
double * GetNodeData (const std::string &label)
 
template<typename TBlock>
void EmplaceBlocks (nimble::DataManager &data_manager, const std::shared_ptr< nimble::MaterialFactoryBase > &material_factory_base)
 
void AllocateInitializeElementData (nimble::DataManager &data_manager, const std::shared_ptr< nimble::MaterialFactoryBase > &material_factory_base)
 

Protected Attributes

std::vector< int > block_ids_
 Block ids.
 
std::map< int, std::shared_ptr< nimble::Block > > blocks_
 Blocks.
 
std::map< int, Fielddata_fields_
 Map key is the field_id, value is the corresponding Field.
 
std::map< int, std::vector< double > > node_data_
 
std::map< int, std::vector< int > > element_data_fields_
 
std::map< int, std::vector< double > > element_data_n_
 
std::map< int, std::vector< double > > element_data_np1_
 
std::vector< int > globally_shared_nodes_
 List of node ids that are shared across multiple ranks.
 
std::map< int, int > global_node_id_to_local_node_id_
 Map from global node it to local node id.
 
std::vector< std::vector< double > > node_data_for_output_
 Information for Exodus output about node data.
 
std::map< int, std::vector< std::vector< double > > > elem_data_for_output_
 Information for Exodus output about element data.
 
std::map< int, std::vector< std::vector< double > > > derived_elem_data_
 Information for Exodus output about element data.
 
- Protected Attributes inherited from nimble::ModelDataBase
int dim_ = 3
 Problem dimension, either 2 or 3.
 
double critical_time_step_ = 0.0
 Critical time step.
 
std::vector< std::string > output_node_component_labels_
 Output labels for node data that will be written to disk.
 
std::map< int, std::vector< std::string > > element_component_labels_
 
std::map< int, std::vector< std::string > > output_element_component_labels_
 Output labels for element data that will be written to disk.
 
std::map< int, std::vector< std::string > > derived_output_element_data_labels_
 Output labels for derived element data that will be written to disk.
 

Constructor & Destructor Documentation

◆ ModelData()

nimble::ModelData::ModelData ( )
default

◆ ~ModelData()

nimble::ModelData::~ModelData ( )
overridedefault

Member Function Documentation

◆ AllocateElementData()

void nimble::ModelData::AllocateElementData ( std::map< int, int > const & num_integration_points_in_each_block)
144{
145 for (std::map<int, std::vector<int>>::const_iterator it = element_data_fields_.begin();
146 it != element_data_fields_.end();
147 it++) {
148 int block_id = it->first;
149 std::vector<int> const& field_ids = it->second;
150 int array_length_for_each_int_point = 0;
151 std::vector<std::string> component_labels_for_block;
152
153 for (const int& field_id : field_ids) {
154 Field field = GetField(field_id);
155 array_length_for_each_int_point += LengthToInt(field.length_, dim_);
156 std::vector<std::string> component_labels = GetComponentLabels(field.label_, field.length_, dim_);
157 component_labels_for_block.insert(
158 component_labels_for_block.end(), component_labels.begin(), component_labels.end());
159 }
160
161 block_ids_.push_back(block_id);
162 element_component_labels_[block_id] = component_labels_for_block;
163 output_element_component_labels_[block_id] = std::vector<std::string>();
164 derived_output_element_data_labels_[block_id] = std::vector<std::string>();
165 int array_length = array_length_for_each_int_point * num_integration_points_in_each_block.at(block_id);
166 element_data_n_[block_id] = std::vector<double>(array_length);
167 element_data_np1_[block_id] = std::vector<double>(array_length);
168 }
169}
int dim_
Problem dimension, either 2 or 3.
Definition nimble_model_data_base.h:328
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::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
std::map< int, std::vector< std::string > > element_component_labels_
Definition nimble_model_data_base.h:338
Field GetField(int field_id)
Definition nimble_model_data.cc:74
std::map< int, std::vector< double > > element_data_n_
Definition nimble_model_data.h:277
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::map< int, std::vector< double > > element_data_np1_
Definition nimble_model_data.h:281
int LengthToInt(Length length, int dim)
Definition nimble_data_utils.cc:57
std::vector< std::string > GetComponentLabels(std::string label, Length length, int dim)
Definition nimble_data_utils.cc:159

◆ AllocateInitializeElementData()

void nimble::ModelData::AllocateInitializeElementData ( nimble::DataManager & data_manager,
const std::shared_ptr< nimble::MaterialFactoryBase > & material_factory_base )
protected
455{
456 const auto& mesh_ = data_manager.GetMesh();
457 const auto& parser_ = data_manager.GetParser();
458
459 auto material_factory_ptr = dynamic_cast<nimble::MaterialFactory*>(material_factory_base.get());
460
461 std::map<int, int> num_elem_in_each_block = mesh_.GetNumElementsInBlock();
462 AllocateElementData(num_elem_in_each_block);
463 SpecifyOutputFields(parser_.GetOutputFieldString());
464 std::map<int, std::vector<std::string>> const& elem_data_labels = GetElementDataLabels();
465 std::map<int, std::vector<std::string>> const& derived_elem_data_labels = GetDerivedElementDataLabelsForOutput();
466
467 // Initialize the element data
468 for (auto& block_it : blocks_) {
469 int block_id = block_it.first;
470 int num_elem_in_block = mesh_.GetNumElementsInBlock(block_id);
471 std::vector<int> const& elem_global_ids = mesh_.GetElementGlobalIdsInBlock(block_id);
472 auto& block = block_it.second;
473 std::vector<double>& elem_data_n = GetElementDataOld(block_id);
474 std::vector<double>& elem_data_np1 = GetElementDataNew(block_id);
475 block->InitializeElementData(
476 num_elem_in_block,
477 elem_global_ids,
478 elem_data_labels.at(block_id),
479 derived_elem_data_labels.at(block_id),
480 elem_data_n,
481 elem_data_np1,
482 *material_factory_ptr,
483 data_manager);
484 }
485}
const nimble::Parser & GetParser() const
Return constant reference to parser information.
Definition nimble_data_manager.h:101
const nimble::GenesisMesh & GetMesh() const
Return constant reference to mesh.
Definition nimble_data_manager.h:110
const std::map< int, std::vector< std::string > > & GetElementDataLabels() const
Definition nimble_model_data_base.h:309
const std::map< int, std::vector< std::string > > & GetDerivedElementDataLabelsForOutput() const
Definition nimble_model_data_base.h:321
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
std::map< int, std::shared_ptr< nimble::Block > > blocks_
Blocks.
Definition nimble_model_data.h:262
void AllocateElementData(std::map< int, int > const &num_integration_points_in_each_block)
Definition nimble_model_data.cc:143
std::vector< double > & GetElementDataNew(int block_id)
Definition nimble_model_data.h:201

◆ AllocateNodeData()

int nimble::ModelData::AllocateNodeData ( Length length,
std::string label,
int num_objects )
overridevirtual

Allocate data storage for a node-based quantity.

Parameters
length
label
num_objects
Returns
Field ID for the data allocated

Implements nimble::ModelDataBase.

81{
82 Field field;
83 field.label_ = label;
84 field.relation_ = NODE;
85 field.length_ = length;
86 AssignFieldId(field);
87 int array_size = num_objects;
88 array_size *= LengthToInt(length, dim_);
89 node_data_[field.id_] = std::vector<double>(array_size);
90 return field.id_;
91}
std::map< int, std::vector< double > > node_data_
Definition nimble_model_data.h:269
void AssignFieldId(Field &field)
Definition nimble_model_data.cc:371
@ NODE
Definition nimble_data_utils.h:60

◆ AssignFieldId()

void nimble::ModelData::AssignFieldId ( Field & field)
protected
372{
373 int field_id = -1;
374 std::string name(field.label_);
375 std::transform(field.label_.begin(), field.label_.end(), name.begin(), ::tolower);
376 for (std::map<int, Field>::const_iterator it = data_fields_.begin(); it != data_fields_.end(); it++) {
377 std::string temp_name(it->second.label_);
378 std::transform(it->second.label_.begin(), it->second.label_.end(), temp_name.begin(), ::tolower);
379 if (name == temp_name) {
380 if (field.relation_ == it->second.relation_ && field.length_ == it->second.length_) {
381 field_id = it->second.id_;
382 break;
383 } else {
385 "\nError: ModelData::AssignFieldId(), Inconsistent fields cannot "
386 "be assigned the same label. Label = " +
387 field.label_ + "\n");
388 }
389 }
390 }
391 if (field_id == -1) {
392 field_id = data_fields_.size();
393 field.id_ = field_id;
394 data_fields_[field_id] = field;
395 } else {
396 field.id_ = field_id;
397 }
398}
std::map< int, Field > data_fields_
Map key is the field_id, value is the corresponding Field.
Definition nimble_model_data.h:265
#define NIMBLE_ABORT(...)
Definition nimble_macros.h:87

◆ ComputeExternalForce()

void nimble::ModelData::ComputeExternalForce ( nimble::DataManager & data_manager,
double time_previous,
double time_current,
bool is_output_step )
overridevirtual

Compute the external force.

Parameters
data_managerReference to the DataManager
time_previous
time_current
is_output_step

Reimplemented from nimble::ModelDataBase.

615{
616 auto force = GetVectorNodeData("external_force");
617 force.zero();
618}
nimble::Viewify< 2 > GetVectorNodeData(int field_id) override
Get view of vector quantity defined on nodes.
Definition nimble_model_data.cc:541

◆ ComputeInternalForce()

void nimble::ModelData::ComputeInternalForce ( nimble::DataManager & data_manager,
double time_previous,
double time_current,
bool is_output_step,
const nimble::Viewify< 2 > & displacement,
nimble::Viewify< 2 > & force )
overridevirtual

Compute the internal force.

Parameters
[in]data_manager
[in]time_previous
[in]time_current
[in]is_output_step
[in]displacement
[out]internal_forceOutput for internal force

Reimplemented from nimble::ModelDataBase.

628{
629 const auto& mesh = data_manager.GetMesh();
630
631 force.zero();
632
633 auto reference_coord = GetNodeData("reference_coordinate");
634 auto velocity = GetNodeData("velocity");
635
636 for (auto& block_it : blocks_) {
637 int block_id = block_it.first;
638 int num_elem_in_block = mesh.GetNumElementsInBlock(block_id);
639 int const* elem_conn = mesh.GetConnectivity(block_id);
640 std::vector<int> const& elem_global_ids = mesh.GetElementGlobalIdsInBlock(block_id);
641 auto& block = block_it.second;
642 std::vector<double> const& elem_data_n = GetElementDataOld(block_id);
643 std::vector<double>& elem_data_np1 = GetElementDataNew(block_id);
644 block->ComputeInternalForce(
645 reference_coord,
646 displacement.data(),
647 velocity,
648 force.data(),
649 time_previous,
650 time_current,
651 num_elem_in_block,
652 elem_conn,
653 elem_global_ids.data(),
654 element_component_labels_.at(block_id),
655 elem_data_n,
656 elem_data_np1,
657 data_manager,
658 is_output_step);
659 }
660
661 // DJL
662 // Perform a vector reduction on internal force. This is a vector nodal
663 // quantity.
664 auto vector_comm = data_manager.GetVectorCommunicator();
665 constexpr int vector_dimension = 3;
666 vector_comm->VectorReduction(vector_dimension, force.data());
667}
std::shared_ptr< nimble::VectorCommunicator > GetVectorCommunicator()
Return shared pointer to VectorCommunicator objet.
Definition nimble_data_manager.h:146
double * GetNodeData(int field_id)
Definition nimble_model_data.cc:94
void zero()
Definition nimble_view.h:116
Scalar * data() const
Definition nimble_view.h:130

◆ ComputeLumpedMass()

void nimble::ModelData::ComputeLumpedMass ( nimble::DataManager & data_manager)
overridevirtual

Compute the lumped mass.

Parameters
data_managerReference to the data manager

Implements nimble::ModelDataBase.

497{
498 const auto& mesh_ = data_manager.GetMesh();
499 const auto& parser_ = data_manager.GetParser();
500
501 auto lumped_mass_field_id = GetFieldId("lumped_mass");
502
503 auto lumped_mass = GetNodeData(lumped_mass_field_id);
504 auto reference_coordinate = GetVectorNodeData("reference_coordinate");
505 auto displacement = GetVectorNodeData("displacement");
506
507 //
508 // Computed the lumped mass matrix (diagonal matrix) and the critical time
509 // step
510 //
511 critical_time_step_ = std::numeric_limits<double>::max();
512 for (auto& block_it : blocks_) {
513 int block_id = block_it.first;
514 int num_elem_in_block = mesh_.GetNumElementsInBlock(block_id);
515 int const* elem_conn = mesh_.GetConnectivity(block_id);
516 auto& block = block_it.second;
517 block->ComputeLumpedMassMatrix(reference_coordinate.data(), num_elem_in_block, elem_conn, lumped_mass);
518 double block_critical_time_step =
519 block->ComputeCriticalTimeStep(reference_coordinate, displacement, num_elem_in_block, elem_conn);
520 if (block_critical_time_step < critical_time_step_) { critical_time_step_ = block_critical_time_step; }
521 }
522
523 //
524 // Perform a vector reduction on lumped mass. This is a scalar nodal
525 // quantity.
526 //
527 auto vector_comm = data_manager.GetVectorCommunicator();
528 constexpr int scalar_dimension = 1;
529 vector_comm->VectorReduction(scalar_dimension, lumped_mass);
530}
double critical_time_step_
Critical time step.
Definition nimble_model_data_base.h:331
int GetFieldId(const std::string &label) const override
Returns the field ID for a specific label.
Definition nimble_model_data.cc:65

◆ DeclareElementData()

void nimble::ModelData::DeclareElementData ( int block_id,
std::vector< std::pair< std::string, Length > > const & data_labels_and_lengths )
127{
128 if (element_data_fields_.find(block_id) == element_data_fields_.end()) {
129 element_data_fields_[block_id] = std::vector<int>();
130 }
131
132 for (std::pair<std::string, Length> const& entry : data_labels_and_lengths) {
133 Field field;
134 field.label_ = entry.first;
135 field.relation_ = ELEMENT;
136 field.length_ = entry.second;
137 AssignFieldId(field);
138 element_data_fields_[block_id].push_back(field.id_);
139 }
140}
@ ELEMENT
Definition nimble_data_utils.h:61

◆ EmplaceBlocks()

template<typename TBlock>
void nimble::ModelData::EmplaceBlocks ( nimble::DataManager & data_manager,
const std::shared_ptr< nimble::MaterialFactoryBase > & material_factory_base )
protected
421{
422 const auto& mesh_ = data_manager.GetMesh();
423 const auto& parser_ = data_manager.GetParser();
424
425 auto material_factory_ptr = dynamic_cast<nimble::MaterialFactory*>(material_factory_base.get());
426
427 const std::vector<int>& block_ids = mesh_.GetBlockIds();
428 for (int block_id : block_ids) {
429 std::string const& model_material_parameters = parser_.GetModelMaterialParameters(block_id);
430 auto block_ptr = std::shared_ptr<nimble::Block>(new TBlock());
431 block_ptr->Initialize(model_material_parameters, *material_factory_ptr);
432 std::vector<std::pair<std::string, nimble::Length>> data_labels_and_lengths;
433 block_ptr->GetDataLabelsAndLengths(data_labels_and_lengths);
434 DeclareElementData(block_id, data_labels_and_lengths);
435 blocks_[block_id] = block_ptr;
436 }
437}
void DeclareElementData(int block_id, std::vector< std::pair< std::string, Length > > const &data_labels_and_lengths)
Definition nimble_model_data.cc:126

◆ GetBlocks() [1/2]

std::map< int, std::shared_ptr< nimble::Block > > & nimble::ModelData::GetBlocks ( )
inline
214 {
215 return blocks_;
216 }

◆ GetBlocks() [2/2]

std::map< int, std::shared_ptr< nimble::Block > > const & nimble::ModelData::GetBlocks ( ) const
inline
220 {
221 return blocks_;
222 }

◆ GetElementDataForOutput()

void nimble::ModelData::GetElementDataForOutput ( std::map< int, std::vector< std::vector< double > > > & single_component_arrays)
173{
174 // Allocate space in single_component_arrays, if necessary
175 for (auto& output_element_component_label : output_element_component_labels_) {
176 int block_id = output_element_component_label.first;
177 if (single_component_arrays.find(block_id) == single_component_arrays.end()) {
178 single_component_arrays[block_id] = std::vector<std::vector<double>>();
179 }
180 unsigned int num_output_fields_for_block = output_element_component_label.second.size();
181 if (single_component_arrays[block_id].size() != num_output_fields_for_block) {
182 single_component_arrays[block_id].resize(num_output_fields_for_block);
183 }
184 }
185
186 // Copy the data, in component form, to single_component_arrays
187 for (auto& output_element_component_label : output_element_component_labels_) {
188 int block_id = output_element_component_label.first;
189 std::vector<std::string> const& output_element_component_labels_for_this_block =
190 output_element_component_label.second;
191 unsigned int num_element_variables = element_component_labels_.at(block_id).size();
192 unsigned int num_output_variables = output_element_component_labels_for_this_block.size();
193 unsigned int array_size = element_data_np1_.at(block_id).size() / num_element_variables;
194 for (unsigned int output_array_index = 0; output_array_index < num_output_variables; output_array_index++) {
195 std::string output_label = output_element_component_labels_for_this_block[output_array_index];
196 std::vector<double>& output_array = single_component_arrays[block_id][output_array_index];
197 if (output_array.size() != array_size) { output_array.resize(array_size); }
198 // determine the offset into the element data array
199 int offset = -1;
200 for (unsigned int i = 0; i < element_component_labels_[block_id].size(); i++) {
201 if (output_label == element_component_labels_[block_id][i]) { offset = i; }
202 }
203 if (offset == -1) {
205 "\n**** Error in ModelData::GetElementDataForOutput(), output "
206 "label not found.\n");
207 }
208 for (int i = 0; i < array_size; i++) {
209 output_array[i] = element_data_np1_[block_id][i * num_element_variables + offset];
210 }
211 }
212 }
213}

◆ GetElementDataNew()

std::vector< double > & nimble::ModelData::GetElementDataNew ( int block_id)
inline
202 {
203 return element_data_np1_.at(block_id);
204 }

◆ GetElementDataOld()

std::vector< double > & nimble::ModelData::GetElementDataOld ( int block_id)
inline
196 {
197 return element_data_n_.at(block_id);
198 }

◆ GetField()

Field nimble::ModelData::GetField ( int field_id)
75{
76 return data_fields_.at(field_id);
77}

◆ GetFieldId()

int nimble::ModelData::GetFieldId ( const std::string & label) const
overridevirtual

Returns the field ID for a specific label.

Parameters
field_labelLabel for a stored quantity
Returns
Field ID to identify the data storage

Implements nimble::ModelDataBase.

66{
67 for (auto const& id_field_pair : data_fields_) {
68 if (id_field_pair.second.label_ == label) { return id_field_pair.first; }
69 }
70 return -1;
71}

◆ GetGloballySharedNodes()

std::vector< int > & nimble::ModelData::GetGloballySharedNodes ( )
inline
226 {
228 }
std::vector< int > globally_shared_nodes_
List of node ids that are shared across multiple ranks.
Definition nimble_model_data.h:284

◆ GetGlobalNodeIdToLocalNodeIdMap()

std::map< int, int > & nimble::ModelData::GetGlobalNodeIdToLocalNodeIdMap ( )
inline
232 {
234 }
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

◆ GetNodeData() [1/2]

double * nimble::ModelData::GetNodeData ( const std::string & label)
protected
600{
601 const auto field_id = GetFieldId(label);
602 if (field_id < 0) {
603 std::string code = " Field " + label + " Not Allocated ";
604 NIMBLE_ABORT(code);
605 }
606 return node_data_.at(field_id).data();
607}

◆ GetNodeData() [2/2]

double * nimble::ModelData::GetNodeData ( int field_id)
95{
96 return node_data_.at(field_id).data();
97}

◆ GetNodeDataComponent()

void nimble::ModelData::GetNodeDataComponent ( int field_id,
int component,
double *const component_data )
protected
402{
403 Field& field = data_fields_.at(field_id);
404 int num_components = LengthToInt(field.length_, dim_);
405 std::vector<double>& data = node_data_.at(field_id);
406
407 if (component >= num_components) {
408 NIMBLE_ABORT("\nError: Invalid component in ModelData::GetNodeDataComponent\n");
409 }
410
411 for (unsigned int i = 0; i < data.size() / num_components; i++) {
412 component_data[i] = data[i * num_components + component];
413 }
414}

◆ GetNodeDataForOutput()

void nimble::ModelData::GetNodeDataForOutput ( std::vector< std::vector< double > > & single_component_arrays)
101{
102 unsigned int number_of_output_fields = output_node_component_labels_.size();
103 if (single_component_arrays.size() != number_of_output_fields) {
104 single_component_arrays.resize(number_of_output_fields);
105 }
106
107 for (unsigned int i_output_label = 0; i_output_label < output_node_component_labels_.size(); i_output_label++) {
108 std::string output_label = output_node_component_labels_[i_output_label];
109 for (std::map<int, std::vector<double>>::const_iterator it = node_data_.begin(); it != node_data_.end(); it++) {
110 Field field = data_fields_.at(it->first);
111 std::vector<std::string> component_labels = GetComponentLabels(field.label_, field.length_, dim_);
112 for (unsigned int i_component = 0; i_component < component_labels.size(); i_component++) {
113 if (component_labels[i_component] == output_label) {
114 int array_size = it->second.size() / LengthToInt(field.length_, dim_);
115 if (single_component_arrays[i_output_label].size() != array_size) {
116 single_component_arrays[i_output_label].resize(array_size);
117 }
118 GetNodeDataComponent(field.id_, i_component, &single_component_arrays[i_output_label][0]);
119 }
120 }
121 }
122 }
123}
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
void GetNodeDataComponent(int field_id, int component, double *const component_data)
Definition nimble_model_data.cc:401

◆ GetScalarNodeData() [1/2]

nimble::Viewify< 1 > nimble::ModelDataBase::GetScalarNodeData ( const std::string & label)
inline

Get view of scalar quantity defined on nodes.

Parameters
labelthe data label
Returns
Viewify<1> object for scalar quantity
147 {
149 };
int GetFieldIdChecked(const std::string &field_label) const
Definition nimble_model_data_base.h:108
nimble::Viewify< 1 > GetScalarNodeData(int field_id) override
Get view of scalar quantity defined on nodes.
Definition nimble_model_data.cc:533

◆ GetScalarNodeData() [2/2]

nimble::Viewify< 1 > nimble::ModelData::GetScalarNodeData ( int field_id)
overridevirtual

Get view of scalar quantity defined on nodes.

Parameters
field_idthe field id (see DataManager::GetFieldIDs())
Returns
Viewify<1> object for scalar quantity

Implements nimble::ModelDataBase.

534{
535 auto& field_vector = node_data_.at(field_id);
536 auto isize = static_cast<int>(field_vector.size());
537 return {field_vector.data(), {isize}, {1}};
538}

◆ GetVectorNodeData() [1/2]

nimble::Viewify< 2 > nimble::ModelDataBase::GetVectorNodeData ( const std::string & label)
inline

Get view of vector quantity defined on nodes.

Parameters
labelthe data label
Returns
Viewify<2> object for vector quantity
164 {
166 }

◆ GetVectorNodeData() [2/2]

nimble::Viewify< 2 > nimble::ModelData::GetVectorNodeData ( int field_id)
overridevirtual

Get view of vector quantity defined on nodes.

Parameters
field_idthe field id (see DataManager::GetFieldIDs())
Returns
Viewify<2> object for vector quantity

Implements nimble::ModelDataBase.

542{
543 auto& field_vector = node_data_.at(field_id);
544 auto isize = static_cast<int>(field_vector.size()) / 3;
545 return {field_vector.data(), {isize, 3}, {3, 1}};
546}

◆ InitializeBlocks()

void nimble::ModelData::InitializeBlocks ( nimble::DataManager & data_manager,
const std::shared_ptr< nimble::MaterialFactoryBase > & material_factory_base )
overridevirtual

Initialize the different blocks in the mesh.

Parameters
data_managerReference to the data manager
material_factory_baseShared pointer to the material factory

Implements nimble::ModelDataBase.

490{
491 EmplaceBlocks<nimble::Block>(data_manager, material_factory_base);
492 AllocateInitializeElementData(data_manager, material_factory_base);
493}
void AllocateInitializeElementData(nimble::DataManager &data_manager, const std::shared_ptr< nimble::MaterialFactoryBase > &material_factory_base)
Definition nimble_model_data.cc:452
template void ModelData::EmplaceBlocks< nimble::Block >(nimble::DataManager &data_manager, const std::shared_ptr< nimble::MaterialFactoryBase > &material_factory_base)

◆ InitializeExodusOutput()

void nimble::ModelData::InitializeExodusOutput ( nimble::DataManager & data_manager)
overridevirtual

Reimplemented from nimble::ModelDataBase.

550{
551 for (auto& block_it : blocks_) {
552 int block_id = block_it.first;
553 derived_elem_data_[block_id] = std::vector<std::vector<double>>();
554 }
555}
std::map< int, std::vector< std::vector< double > > > derived_elem_data_
Information for Exodus output about element data.
Definition nimble_model_data.h:296

◆ SpecifyOutputFields()

void nimble::ModelData::SpecifyOutputFields ( const std::string & output_field_string)
217{
218 // Parse the string into individual field labels
219 std::vector<std::string> requested_output_labels;
220 std::stringstream ss(output_field_string);
221 std::string entry;
222 while (std::getline(ss, entry, ' ')) { requested_output_labels.push_back(entry); }
223
224 std::vector<std::string> node_noncomponent_labels;
225 std::vector<std::string> node_component_labels;
226 std::vector<std::string> element_noncomponent_labels;
227 std::vector<std::string> element_component_labels;
228 std::vector<std::string> element_int_pt_noncomponent_labels;
229 std::vector<std::string> element_int_pt_component_labels;
230 for (std::map<int, Field>::const_iterator field_it = data_fields_.begin(); field_it != data_fields_.end();
231 field_it++) {
232 std::string label = field_it->second.label_;
233 Length length = field_it->second.length_;
234 Relation relation = field_it->second.relation_;
235 if (relation == NODE) {
236 node_noncomponent_labels.push_back(label);
237 std::vector<std::string> component_labels = GetComponentLabels(label, length, dim_);
238 for (const auto& component_label : component_labels) { node_component_labels.push_back(component_label); }
239 } else if (relation == ELEMENT) {
240 if (!HasIntegrationPointPrefix(label)) {
242 "\n**** Error, ModelData::SpecifyOutputFields() expected "
243 "integration point prefix on data label \"" +
244 label + "\".\n");
245 }
246 element_int_pt_noncomponent_labels.push_back(label);
247 std::vector<std::string> int_pt_component_labels = GetComponentLabels(label, length, dim_);
248 for (const auto& int_pt_component_label : int_pt_component_labels) {
249 element_int_pt_component_labels.push_back(int_pt_component_label);
250 }
251 std::string label_without_prefix = RemoveIntegrationPointPrefix(label);
252 if (std::find(element_noncomponent_labels.begin(), element_noncomponent_labels.end(), label_without_prefix) ==
253 element_noncomponent_labels.end()) {
254 element_noncomponent_labels.push_back(label_without_prefix);
255 std::vector<std::string> component_labels = GetComponentLabels(label_without_prefix, length, dim_);
256 for (const auto& component_label : component_labels) { element_component_labels.push_back(component_label); }
257 }
258 }
259 }
260
261 // Record the field labels for output
262 for (auto const& requested_label : requested_output_labels) {
263 // Requested label is node component data
264 if (std::find(node_component_labels.begin(), node_component_labels.end(), requested_label) !=
265 node_component_labels.end()) {
266 output_node_component_labels_.push_back(requested_label);
267 }
268
269 // Requested label is a vector or tensor at a node (output all the
270 // vector/tensor components)
271 else if (
272 std::find(node_noncomponent_labels.begin(), node_noncomponent_labels.end(), requested_label) !=
273 node_noncomponent_labels.end()) {
274 Length length = LabelToLength(requested_label, data_fields_, dim_);
275 std::vector<std::string> component_labels = GetComponentLabels(requested_label, length, dim_);
276 for (auto const& label : component_labels) { output_node_component_labels_.push_back(label); }
277 }
278
279 // Requested label is a single component of a vector or tensor at the
280 // integration points that will be volume averaged over the element
281 else if (
282 std::find(element_component_labels.begin(), element_component_labels.end(), requested_label) !=
283 element_component_labels.end()) {
284 for (auto const& block_id_label_pair : element_component_labels_) {
285 int block_id = block_id_label_pair.first;
286 bool label_exists_on_block = false;
287 for (auto const& label_on_block : block_id_label_pair.second) {
288 if (requested_label == RemoveIntegrationPointPrefix(label_on_block)) { label_exists_on_block = true; }
289 }
290 if (label_exists_on_block) { derived_output_element_data_labels_.at(block_id).push_back(requested_label); }
291 }
292 }
293
294 // Requested label matches a component label at a specific integration point
295 else if (
296 std::find(element_int_pt_component_labels.begin(), element_int_pt_component_labels.end(), requested_label) !=
297 element_int_pt_component_labels.end()) {
298 for (auto const& block_id_label_pair : element_component_labels_) {
299 int block_id = block_id_label_pair.first;
300 bool label_exists_on_block = false;
301 for (auto const& label_on_block : block_id_label_pair.second) {
302 if (requested_label == label_on_block) { label_exists_on_block = true; }
303 }
304 if (label_exists_on_block) { output_element_component_labels_.at(block_id).push_back(requested_label); }
305 }
306 }
307
308 // Requested label is for a scalar, vector, or tensor at the integration
309 // points that will be volume averaged over the element (output all the
310 // vector/tensor components)
311 else if (
312 std::find(element_noncomponent_labels.begin(), element_noncomponent_labels.end(), requested_label) !=
313 element_noncomponent_labels.end()) {
314 Length length = LabelToLength(requested_label, data_fields_, dim_);
315 std::vector<std::string> component_labels = GetComponentLabels(requested_label, length, dim_);
316 for (auto const& label : component_labels) {
317 for (auto const& it : element_component_labels_) {
318 int block_id = it.first;
319 std::vector<std::string> const& available_element_component_labels_for_block = it.second;
320 for (auto const& available_label : available_element_component_labels_for_block) {
321 std::string label_without_int_pt_prefix = RemoveIntegrationPointPrefix(available_label);
322 if (label == label_without_int_pt_prefix) {
323 if (std::find(
324 derived_output_element_data_labels_.at(block_id).begin(),
325 derived_output_element_data_labels_.at(block_id).end(),
326 label) == derived_output_element_data_labels_.at(block_id).end()) {
327 derived_output_element_data_labels_.at(block_id).push_back(label);
328 }
329 }
330 }
331 }
332 }
333 }
334
335 // Requested label is for a scalar, vector, or tensor at a specific
336 // integration point (output all the vector/tensor components)
337 else if (
338 std::find(
339 element_int_pt_noncomponent_labels.begin(), element_int_pt_noncomponent_labels.end(), requested_label) !=
340 element_int_pt_noncomponent_labels.end()) {
341 Length length = LabelToLength(requested_label, data_fields_, dim_);
342 std::vector<std::string> component_labels = GetComponentLabels(requested_label, length, dim_);
343 for (auto const& label : component_labels) {
344 for (auto const& it : element_component_labels_) {
345 int block_id = it.first;
346 std::vector<std::string> const& available_element_component_labels_for_block = it.second;
347 for (auto const& available_label : available_element_component_labels_for_block) {
348 if (label == available_label) { output_element_component_labels_.at(block_id).push_back(label); }
349 }
350 }
351 }
352 }
353
354 // Special cases
355 else if (requested_label == "volume") {
356 for (auto const& block_id : block_ids_) {
357 derived_output_element_data_labels_.at(block_id).push_back(requested_label);
358 }
359 }
360
361 else {
363 "\nError: ModelData::SpecifyOutputFields(), unable to process "
364 "requested output \"" +
365 requested_label + "\".\n");
366 }
367 }
368}
std::string RemoveIntegrationPointPrefix(std::string label)
Definition nimble_data_utils.cc:99
Length LabelToLength(std::string label, std::map< int, Field > const &data_fields, int dim)
Definition nimble_data_utils.cc:269
Length
Definition nimble_data_utils.h:66
Relation
Definition nimble_data_utils.h:58
bool HasIntegrationPointPrefix(std::string label)
Definition nimble_data_utils.cc:124

◆ UpdateStates()

void nimble::ModelData::UpdateStates ( const nimble::DataManager & data_manager)
inlineoverridevirtual

Copy time state (n+1) into time state (n)

Parameters
data_managerReference to the data manager

Implements nimble::ModelDataBase.

105 {
107 }

◆ WriteExodusOutput()

void nimble::ModelData::WriteExodusOutput ( nimble::DataManager & data_manager,
double time_current )
overridevirtual

Write output of simulation in Exodus format.

Parameters
[in]data_managerReference to data manager
[in]time_currentTime value

Reimplemented from nimble::ModelDataBase.

559{
560 const auto& mesh_ = data_manager.GetMesh();
561 auto exodus_output = data_manager.GetExodusOutput();
562
563 std::vector<double> global_data;
564
565 auto reference_coord_ = GetNodeData("reference_coordinate");
566 auto displacement = GetNodeData("displacement");
567
568 for (auto& block_it : blocks_) {
569 int block_id = block_it.first;
570 auto block = block_it.second;
571 int num_elem_in_block = mesh_.GetNumElementsInBlock(block_id);
572 int const* elem_conn = mesh_.GetConnectivity(block_id);
573 const auto& elem_data_np1 = GetElementDataNew(block_id);
574 block->ComputeDerivedElementData(
575 reference_coord_,
576 displacement,
577 num_elem_in_block,
578 elem_conn,
579 element_component_labels_.at(block_id).size(),
580 elem_data_np1,
581 derived_output_element_data_labels_.at(block_id).size(),
582 derived_elem_data_.at(block_id));
583 }
584
587
588 exodus_output->WriteStep(
589 time_current,
590 global_data,
596}
std::shared_ptr< nimble::ExodusOutput > GetExodusOutput()
Definition nimble_data_manager.h:158
void GetElementDataForOutput(std::map< int, std::vector< std::vector< double > > > &single_component_arrays)
Definition nimble_model_data.cc:172
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::vector< std::vector< double > > node_data_for_output_
Information for Exodus output about node data.
Definition nimble_model_data.h:290
void GetNodeDataForOutput(std::vector< std::vector< double > > &single_component_arrays)
Definition nimble_model_data.cc:100

Member Data Documentation

◆ block_ids_

std::vector<int> nimble::ModelData::block_ids_
protected

Block ids.

◆ blocks_

std::map<int, std::shared_ptr<nimble::Block> > nimble::ModelData::blocks_
protected

Blocks.

◆ data_fields_

std::map<int, Field> nimble::ModelData::data_fields_
protected

Map key is the field_id, value is the corresponding Field.

◆ derived_elem_data_

std::map<int, std::vector<std::vector<double> > > nimble::ModelData::derived_elem_data_
protected

Information for Exodus output about element data.

◆ elem_data_for_output_

std::map<int, std::vector<std::vector<double> > > nimble::ModelData::elem_data_for_output_
protected

Information for Exodus output about element data.

◆ element_data_fields_

std::map<int, std::vector<int> > nimble::ModelData::element_data_fields_
protected

Map key is the block_id, the vector contains the field ids for the fields on that block.

◆ element_data_n_

std::map<int, std::vector<double> > nimble::ModelData::element_data_n_
protected

Map key is the block_id, vector contains full data array for that block at step N.

◆ element_data_np1_

std::map<int, std::vector<double> > nimble::ModelData::element_data_np1_
protected

Map key is the block_id, vector contains full data array for that block at step N+1.

◆ global_node_id_to_local_node_id_

std::map<int, int> nimble::ModelData::global_node_id_to_local_node_id_
protected

Map from global node it to local node id.

◆ globally_shared_nodes_

std::vector<int> nimble::ModelData::globally_shared_nodes_
protected

List of node ids that are shared across multiple ranks.

◆ node_data_

std::map<int, std::vector<double> > nimble::ModelData::node_data_
protected

Map key is the field_id, vector contains the nested data array for the given nodal field.

◆ node_data_for_output_

std::vector<std::vector<double> > nimble::ModelData::node_data_for_output_
protected

Information for Exodus output about node data.


The documentation for this class was generated from the following files: