----------------------------------------------------------------------------
| 1044 | |
| 1045 | //---------------------------------------------------------------------------- |
| 1046 | bool AddFieldData(vtkDataObject* output, const conduit_cpp::Node& stateFields, bool isAMReX) |
| 1047 | { |
| 1048 | auto field_data = output->GetFieldData(); |
| 1049 | auto number_of_children = stateFields.number_of_children(); |
| 1050 | for (conduit_index_t child_index = 0; child_index < number_of_children; ++child_index) |
| 1051 | { |
| 1052 | auto field_node = stateFields.child(child_index); |
| 1053 | const std::string& fieldName = field_node.name(); |
| 1054 | |
| 1055 | try |
| 1056 | { |
| 1057 | std::size_t dataset_size = 0; |
| 1058 | if (field_node.number_of_children() == 0) |
| 1059 | { |
| 1060 | dataset_size = field_node.dtype().number_of_elements(); |
| 1061 | } |
| 1062 | else |
| 1063 | { |
| 1064 | dataset_size = field_node.child(0).dtype().number_of_elements(); |
| 1065 | } |
| 1066 | |
| 1067 | if (dataset_size > 0) |
| 1068 | { |
| 1069 | vtkSmartPointer<vtkAbstractArray> dataArray; |
| 1070 | if (field_node.dtype().is_string()) |
| 1071 | { |
| 1072 | auto stringArray = vtkSmartPointer<vtkStringArray>::New(); |
| 1073 | stringArray->SetNumberOfTuples(1); |
| 1074 | stringArray->SetValue(0, field_node.as_string().c_str()); |
| 1075 | dataArray = stringArray; |
| 1076 | dataArray->SetName(fieldName.c_str()); |
| 1077 | } |
| 1078 | else |
| 1079 | { |
| 1080 | dataArray = vtkConduitArrayUtilities::MCArrayToVTKArray( |
| 1081 | conduit_cpp::c_node(&field_node), fieldName); |
| 1082 | } |
| 1083 | |
| 1084 | if (dataArray) |
| 1085 | { |
| 1086 | if (isAMReX) |
| 1087 | { |
| 1088 | auto ug = vtkUniformGrid::SafeDownCast(output); |
| 1089 | const auto vtk_association = GetAssociation(field_node["association"].as_string()); |
| 1090 | auto dsa = ug->GetAttributes(vtk_association); |
| 1091 | dsa->AddArray(dataArray); |
| 1092 | } |
| 1093 | else |
| 1094 | { |
| 1095 | field_data->AddArray(dataArray); |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | if ((fieldName == "time" || fieldName == "TimeValue") && field_node.dtype().is_number()) |
| 1100 | { |
| 1101 | // let's also set DATA_TIME_STEP. |
| 1102 | output->GetInformation()->Set(vtkDataObject::DATA_TIME_STEP(), field_node.to_float64()); |
| 1103 | } |
no test coverage detected