@@ -965,29 +965,11 @@ It is simple to ask what the layout representation is, and often code will branc
965965 The next tool in the tool box are material set conversions.
966966A material set conforming to any of the material set layout types can be provided and converted into a material set with a different layout type:
967967
968- .. code :: cpp
969-
970- //-------------------------------------------------------------------------
971- // creates a multi-buffer non-sparse case
972- void CONDUIT_BLUEPRINT_API to_multi_buffer_by_element(const conduit::Node &src_matset,
973- conduit::Node &dest_matset);
974-
975- //-------------------------------------------------------------------------
976- // creates a uni-buffer sparse case with 1st index into elements
977- void CONDUIT_BLUEPRINT_API to_uni_buffer_by_element(const conduit::Node &src_matset,
978- conduit::Node &dest_matset,
979- const float64 epsilon = CONDUIT_EPSILON);
980-
981- //-------------------------------------------------------------------------
982- // creates a multi-buffer sparse case with 1st index into materials
983- void CONDUIT_BLUEPRINT_API to_multi_buffer_by_material(const conduit::Node &src_matset,
984- conduit::Node &dest_matset,
985- const float64 epsilon = CONDUIT_EPSILON);
986- //-------------------------------------------------------------------------
987- // throws an error as this case is not supported
988- void CONDUIT_BLUEPRINT_API to_uni_buffer_by_material(const conduit::Node &src_matset,
989- conduit::Node &dest_matset,
990- const float64 epsilon = CONDUIT_EPSILON);
968+ .. literalinclude :: ../../libs/blueprint/conduit_blueprint_mesh.hpp
969+ :start-after: _matset_layout_conversions_start
970+ :end-before: _matset_layout_conversions_end
971+ :language: cpp
972+ :dedent: 4
991973
992974These are similarly simple to use:
993975
@@ -1015,13 +997,11 @@ These are similarly simple to use:
1015997
1016998 It is also possible to convert material sets to a `Silo <https://silo.readthedocs.io/en/latest/ >`_-like mixed slot representation:
1017999
1018- .. code :: cpp
1019-
1020- //-------------------------------------------------------------------------
1021- void CONDUIT_BLUEPRINT_API to_silo(const conduit::Node &matset,
1022- conduit::Node &dest,
1023- const float64 epsilon = CONDUIT_EPSILON);
1024-
1000+ .. literalinclude :: ../../libs/blueprint/conduit_blueprint_mesh.hpp
1001+ :start-after: _matset_to_silo_start
1002+ :end-before: _matset_to_silo_end
1003+ :language: cpp
1004+ :dedent: 4
10251005
10261006This will create an output with the following information:
10271007
@@ -1054,49 +1034,27 @@ This will create an output with the following information:
10541034
10551035Conduit also provides tools for creating/fetching material maps:
10561036
1057- .. code :: cpp
1058-
1059- //-------------------------------------------------------------------------
1060- // this will use set external if the matmap already exists
1061- void CONDUIT_BLUEPRINT_API create_or_reuse_material_map(const conduit::Node &matset,
1062- conduit::Node &material_map);
1063- //-------------------------------------------------------------------------
1064- // this will use set if the matmap already exists
1065- void CONDUIT_BLUEPRINT_API create_or_copy_material_map(const conduit::Node &matset,
1066- conduit::Node &material_map);
1037+ .. literalinclude :: ../../libs/blueprint/conduit_blueprint_mesh.hpp
1038+ :start-after: _matset_create_matmap_methods_start
1039+ :end-before: _matset_create_matmap_methods_end
1040+ :language: cpp
1041+ :dedent: 4
10671042
10681043And tools for renumbering material ids to be in the range ``[0, N-1] ``, where ``N `` is the number of materials:
10691044
1070- .. code :: cpp
1071-
1072- //-------------------------------------------------------------------------
1073- // renumbers material ids to run between 0 and N-1 where N is the number of
1074- // materials.
1075- void CONDUIT_BLUEPRINT_API renumber_material_ids(const conduit::Node &src_matset,
1076- conduit::Node &dest_matset);
1077- //-------------------------------------------------------------------------
1078- // renumbers material ids to run between 0 and N-1 where N is the number of
1079- // materials.
1080- void CONDUIT_BLUEPRINT_API renumber_material_ids(conduit::Node &matset);
1081-
1082- Conduit also provides some general information methods:
1083-
1084- .. code :: cpp
1045+ .. literalinclude :: ../../libs/blueprint/conduit_blueprint_mesh.hpp
1046+ :start-after: _matset_renumber_mat_ids_start
1047+ :end-before: _matset_renumber_mat_ids_end
1048+ :language: cpp
1049+ :dedent: 4
10851050
1086- //-------------------------------------------------------------------------
1087- // renumbers material ids to run between 0 and N-1 where N is the number of
1088- // materials.
1089- void CONDUIT_BLUEPRINT_API renumber_material_ids(conduit::Node &matset);
1090- //-------------------------------------------------------------------------
1091- index_t CONDUIT_BLUEPRINT_API count_elements_from_matset(const conduit::Node &matset);
1092- //-------------------------------------------------------------------------
1093- index_t CONDUIT_BLUEPRINT_API count_materials_from_matset(const conduit::Node &matset);
1094- //-------------------------------------------------------------------------
1095- bool CONDUIT_BLUEPRINT_API is_material_in_element(const conduit::Node &matset,
1096- const std::string &matname,
1097- const index_t elem_id,
1098- const float64 epsilon = CONDUIT_EPSILON);
1051+ Conduit Blueprint also provides some general information methods:
10991052
1053+ .. literalinclude :: ../../libs/blueprint/conduit_blueprint_mesh.hpp
1054+ :start-after: _matset_info_methods_start
1055+ :end-before: _matset_info_methods_end
1056+ :language: cpp
1057+ :dedent: 4
11001058
11011059
11021060Material Set Accessors
@@ -1116,47 +1074,31 @@ We can ask questions about how the ``MatsetAccessor`` was created:
11161074
11171075 MatsetAccessor m_acc1 = MatsetAccessor(matset);
11181076 if (m_acc1.has_field())
1119- {
11201077 std::cout << "matset accessor 1 has field" << std::endl;
1121- }
11221078 if (m_acc1.has_specset())
1123- {
11241079 std::cout << "matset accessor 1 has specset" << std::endl;
1125- }
11261080
11271081 MatsetAccessor m_acc2 = MatsetAccessor(matset, field);
11281082 if (m_acc2.has_field())
1129- {
11301083 std::cout << "matset accessor 2 has field" << std::endl;
1131- }
11321084 if (m_acc2.has_specset())
1133- {
11341085 std::cout << "matset accessor 2 has specset" << std::endl;
1135- }
11361086
11371087 MatsetAccessor m_acc3 = MatsetAccessor(matset, specset);
11381088 if (m_acc3.has_field())
1139- {
11401089 std::cout << "matset accessor 3 has field" << std::endl;
1141- }
11421090 if (m_acc3.has_specset())
1143- {
11441091 std::cout << "matset accessor 3 has specset" << std::endl;
1145- }
11461092
11471093 MatsetAccessor m_acc4 = MatsetAccessor(matset, field, specset);
11481094 if (m_acc4.has_field())
1149- {
11501095 std::cout << "matset accessor 4 has field" << std::endl;
1151- }
11521096 if (m_acc4.has_specset())
1153- {
11541097 std::cout << "matset accessor 4 has specset" << std::endl;
1155- }
11561098
11571099 This produces the following:
11581100
1159- .. code :: cpp
1101+ .. code :: text
11601102
11611103 matset accessor 2 has field
11621104 matset accessor 3 has specset
@@ -1171,8 +1113,8 @@ We can also ask about general matset information:
11711113
11721114 MatsetAccessor m_acc = MatsetAccessor(matset);
11731115 // buffer style
1174- bool is_uni_buffer = m_acc.is_uni_buffer();
1175- bool is_multi_buffer = m_acc.is_multi_buffer();
1116+ bool is_uni_buffer = m_acc.is_uni_buffer();
1117+ bool is_multi_buffer = m_acc.is_multi_buffer();
11761118
11771119 // dominance
11781120 bool is_element_dominant = m_acc.is_element_dominant();
@@ -1187,18 +1129,25 @@ Once we start writing loops over elements and materials, the indices of those lo
11871129An element index means something different depending on what matset layout we are working with, as does a material index.
11881130
11891131 * For a **multi-buffer ** **element-dominant ** material set
1132+
11901133 * elements range from ``0 `` to the number of elements
11911134 * materials range from ``0 `` to the number of materials (these are material indices, not material identifiers)
11921135 * species range from ``0 `` to the number of species for a given material
1136+
11931137 * For a **multi-buffer ** **material-dominant ** material set
1138+
11941139 * elements range from ``0 `` to the number of elements for a given material
11951140 * materials range from ``0 `` to the number of materials (these are material indices, not material identifiers)
11961141 * species range from ``0 `` to the number of species for a given material
1142+
11971143 * For a **uni-buffer ** **element-dominant ** material set
1144+
11981145 * elements range from ``0 `` to the number of elements
11991146 * materials range from ``0 `` to the number of materials in a given element (these are material indices, not material identifiers)
12001147 * species range from ``0 `` to the number of species for a given material in a given element
1148+
12011149 * For a **uni-buffer ** **mateiral-dominant ** material set
1150+
12021151 * indexing does not matter currently as this case is unsupported
12031152
12041153**Element-dominant ** material sets are easiest to walk by element, and **material-dominant ** material sets are easiest to walk by material.
@@ -1219,16 +1168,21 @@ Here is an example of walking a material set and performing data retrieval using
12191168 const index_t num_mats = m_acc.num_mats();
12201169 for (index_t mat_idx = 0; mat_idx < num_mats; mat_idx ++)
12211170 {
1222- const index_t mat_id = m_acc.get_mat_id(elem_idx, mat_idx);
1223- const index_t mat_order_id = m_acc.get_mat_order_id(elem_idx, mat_idx);
1224- const index_t elem_id = m_acc.get_elem_id(elem_idx, mat_idx);
1171+ // in a multi-buffer by element matset, these values
1172+ // only have meaning if vol_frac > 0
12251173 const float64 vol_frac = m_acc.get_vol_frac(elem_idx, mat_idx);
1226- const float64 mset_val = m_acc.get_mset_val(elem_idx, mat_idx);
1227-
1228- const index_t num_specs_for_mat = m_acc.num_spec_for_mat(elem_idx, mat_idx);
1229- for (index_t spec_idx = 0; spec_idx < num_specs_for_mat; spec_idx ++)
1174+ if (vol_frac > 0.0)
12301175 {
1231- const float64 mf_val = m_acc.get_mass_frac(elem_idx, mat_idx, spec_idx);
1176+ const index_t mat_id = m_acc.get_mat_id(elem_idx, mat_idx);
1177+ const index_t mat_order_id = m_acc.get_mat_order_id(elem_idx, mat_idx);
1178+ const index_t elem_id = m_acc.get_elem_id(elem_idx, mat_idx);
1179+ const float64 mset_val = m_acc.get_mset_val(elem_idx, mat_idx);
1180+
1181+ const index_t num_specs_for_mat = m_acc.num_spec_for_mat(elem_idx, mat_idx);
1182+ for (index_t spec_idx = 0; spec_idx < num_specs_for_mat; spec_idx ++)
1183+ {
1184+ const float64 mf_val = m_acc.get_mass_frac(elem_idx, mat_idx, spec_idx);
1185+ }
12321186 }
12331187 }
12341188 }
@@ -1240,6 +1194,7 @@ Here is an example of walking a material set and performing data retrieval using
12401194 for (index_t mat_idx = 0; mat_idx < num_mats; mat_idx ++)
12411195 {
12421196 // we ask for the number of elements for this material
1197+ // this method is only valid for material dominant matsets
12431198 const index_t num_elems_for_mat = m_acc.num_elems_for_mat(mat_idx);
12441199 for (index_t elem_idx = 0; elem_idx < num_elems_for_mat; elem_idx ++)
12451200 {
@@ -1264,6 +1219,7 @@ Here is an example of walking a material set and performing data retrieval using
12641219 for (index_t elem_idx = 0; elem_idx < num_elems; elem_idx ++)
12651220 {
12661221 // we ask for the number of materials in this element
1222+ // this method is only valid for sparse element dominant matsets
12671223 const index_t num_mats_for_elem = m_acc.num_mats_for_elem(elem_idx);
12681224 for (index_t mat_idx = 0; mat_idx < num_mats_for_elem; mat_idx ++)
12691225 {
0 commit comments