@@ -1047,217 +1047,6 @@ determine_num_elems_in_multi_buffer_by_material(const conduit::Node &elem_ids)
10471047 return static_cast <int >(elem_ids_set.size ());
10481048}
10491049
1050- // -----------------------------------------------------------------------------
1051- void
1052- walk_uni_buffer_by_element_to_multi_buffer_by_element (
1053- const conduit::Node &src_matset,
1054- const std::map<int , std::string> &reverse_matmap,
1055- float64_accessor &values, // can be either vol fracs or matset vals
1056- int64_accessor &material_ids,
1057- std::map<std::string, std::vector<float64>> &new_vals)
1058- {
1059- auto o2m_idx = o2mrelation::O2MIndex (src_matset);
1060- const int num_elems = o2m_idx.size ();
1061-
1062- // initialize sizes
1063- for (const auto & mapitem : reverse_matmap)
1064- {
1065- const std::string &matname = mapitem.second ;
1066- new_vals[matname] = std::vector<float64>(num_elems);
1067- }
1068-
1069- // iterate through matset
1070- for (int elem_id = 0 ; elem_id < num_elems; elem_id ++)
1071- {
1072- for (index_t many_id = 0 ; many_id < o2m_idx.size (elem_id); many_id ++)
1073- {
1074- const index_t data_index = o2m_idx.index (elem_id, many_id);
1075-
1076- const float64 val = values[data_index];
1077- const int mat_id = material_ids[data_index];
1078- const std::string &matname = reverse_matmap.at (mat_id);
1079- new_vals[matname][elem_id] = val;
1080- }
1081- }
1082- }
1083-
1084- // -----------------------------------------------------------------------------
1085- template <typename SaveFunc>
1086- void
1087- walk_uni_buffer_by_element_to_multi_buffer_by_element_specset (
1088- const conduit::Node &src_matset,
1089- const conduit::Node &src_specset,
1090- const std::map<int , std::string> &reverse_matmap,
1091- float64_accessor &matset_values,
1092- int64_accessor &material_ids,
1093- SaveFunc save)
1094- {
1095- // Create one to many index objects to index into the sparse by element
1096- // matset and specset.
1097- auto o2m_matset_idx = o2mrelation::O2MIndex (src_matset);
1098- auto o2m_specset_idx = o2mrelation::O2MIndex (src_specset);
1099-
1100- const int num_elems = o2m_matset_idx.size ();
1101-
1102- // iterate through matset
1103- for (int elem_id = 0 ; elem_id < num_elems; elem_id ++)
1104- {
1105- // Based on the element id, we can query how many materials there
1106- // are in the current zone.
1107- const index_t num_mats_in_zone = o2m_matset_idx.size (elem_id);
1108-
1109- // Each time we step through a material, we need to track how far
1110- // in the species matset_values we have read for that zone.
1111- // So if a zone has some number of materials and each have a
1112- // different number of species, then we need to track how many
1113- // values we have read for the materials that came before.
1114- int material_offset = 0 ;
1115-
1116- // iterate through the materials in this zone
1117- for (index_t local_mat_id = 0 ; local_mat_id < num_mats_in_zone; local_mat_id ++)
1118- {
1119- // what is the index into the material ids array
1120- const index_t material_ids_index = o2m_matset_idx.index (elem_id, local_mat_id);
1121-
1122- // what is the real material id
1123- const int mat_id = material_ids[material_ids_index];
1124-
1125- // fetch the material name
1126- const std::string &matname = reverse_matmap.at (mat_id);
1127-
1128- // fetch the number of species for this material
1129- const int num_species_for_this_material = src_specset[" species_names" ][matname].number_of_children ();
1130-
1131- // iterate through each species for the current material
1132- for (int spec_val_idx = 0 ; spec_val_idx < num_species_for_this_material; spec_val_idx ++)
1133- {
1134- // fetch the species name from the original specset (based on the order
1135- // the names appear in the species_names)
1136- const std::string &specname = src_specset[" species_names" ][matname].child (spec_val_idx).name ();
1137-
1138- // We need an index that is between 0 and the number of species in this zone.
1139- // The way to calculate this is to add our running sum (material_offset)
1140- // with the current species value index, which ranges between 0 and the
1141- // number of species for this material.
1142- const int local_spec_id = material_offset + spec_val_idx;
1143-
1144- // Now we can provide the one (element id) to many (species in element)
1145- // relation with our element id and the local species index, which is
1146- // an index into the number of species in this element. The result is
1147- // an index into the "matset_values", which store species mass fractions.
1148- const index_t spec_mf_idx = o2m_specset_idx.index (elem_id, local_spec_id);
1149-
1150- // fetch the species mass fraction
1151- const float64 val = matset_values[spec_mf_idx];
1152-
1153- // save the species mass fraction in its new home
1154- save (matname, specname, elem_id, val);
1155- }
1156-
1157- // we have read num species, now we must move our offset
1158- material_offset += num_species_for_this_material;
1159- }
1160- }
1161- }
1162-
1163- // -----------------------------------------------------------------------------
1164- template <typename T>
1165- void
1166- read_from_map_write_out (std::map<std::string, std::vector<T>> &datamap,
1167- conduit::Node &destination)
1168- {
1169- for (auto & mapitem : datamap)
1170- {
1171- const std::string &key = mapitem.first ;
1172- const std::vector<T> &data_vector = mapitem.second ;
1173-
1174- destination[key].set (data_vector);
1175- }
1176- }
1177-
1178- // -----------------------------------------------------------------------------
1179- // takes sparse by material data and stores it in a map
1180- void
1181- create_sbm_rep (const conduit::Node &elem_id_src,
1182- const conduit::Node &values_src,
1183- std::map<std::string, std::pair<int64_accessor, float64_accessor>> &sbm_rep)
1184- {
1185- auto eid_itr = elem_id_src.children ();
1186- while (eid_itr.has_next ())
1187- {
1188- const Node &mat_elem_ids = eid_itr.next ();
1189- const std::string matname = eid_itr.name ();
1190- sbm_rep[matname].first = mat_elem_ids.value ();
1191- }
1192-
1193- auto val_itr = values_src.children ();
1194- while (val_itr.has_next ())
1195- {
1196- const Node &values = val_itr.next ();
1197- const std::string matname = val_itr.name ();
1198- sbm_rep[matname].second = values.value ();
1199- }
1200- }
1201-
1202- // -----------------------------------------------------------------------------
1203- // takes sparse by material data and stores it in a map
1204- void
1205- create_sbm_specset_rep (const conduit::Node &elem_id_src,
1206- const conduit::Node &values_src,
1207- std::map<std::string, std::pair<int64_accessor, std::map<std::string, float64_accessor>>> &sbm_rep)
1208- {
1209- auto eid_itr = elem_id_src.children ();
1210- while (eid_itr.has_next ())
1211- {
1212- const Node &mat_elem_ids = eid_itr.next ();
1213- const std::string matname = eid_itr.name ();
1214- sbm_rep[matname].first = mat_elem_ids.value ();
1215- }
1216-
1217- auto val_itr = values_src.children ();
1218- while (val_itr.has_next ())
1219- {
1220- const Node &mset_vals = val_itr.next ();
1221- const std::string matname = val_itr.name ();
1222-
1223- auto spec_itr = mset_vals.children ();
1224- while (spec_itr.has_next ())
1225- {
1226- const Node &spec_mf = spec_itr.next ();
1227- const std::string specname = spec_itr.name ();
1228-
1229- sbm_rep[matname].second [specname] = spec_mf.value ();
1230- }
1231- }
1232- }
1233-
1234- // -----------------------------------------------------------------------------
1235- void
1236- sbm_rep_to_full (const std::map<std::string, std::pair<int64_accessor, float64_accessor>> &sbm_rep,
1237- const int num_elems,
1238- conduit::Node &destination)
1239- {
1240- for (const auto &mapitem : sbm_rep)
1241- {
1242- const std::string &matname = mapitem.first ;
1243- const int64_accessor sbm_eids = mapitem.second .first ;
1244- const float64_accessor sbm_vals = mapitem.second .second ;
1245-
1246- destination[matname].set (DataType::float64 (num_elems));
1247- float64_array dest_data = destination[matname].value ();
1248- dest_data.fill (0.0 );
1249-
1250- const int num_vf = sbm_vals.dtype ().number_of_elements ();
1251- for (int mat_vf_id = 0 ; mat_vf_id < num_vf; mat_vf_id ++)
1252- {
1253- const int elem_id = sbm_eids[mat_vf_id];
1254- const float64 value = sbm_vals[mat_vf_id];
1255-
1256- dest_data[elem_id] = value;
1257- }
1258- }
1259- }
1260-
12611050// -----------------------------------------------------------------------------
12621051// venn full -> sparse by element
12631052void
0 commit comments