Skip to content

Commit b476ab0

Browse files
merge develop
2 parents 99b47cd + c4d4936 commit b476ab0

3 files changed

Lines changed: 243 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s
5151
- Field/Species Set conversion routines (`to_multi_buffer_by_element()`, `to_uni_buffer_by_element()`, and `to_multi_buffer_by_material()`) previously forced materials to appear in the same order in fields/specsets as they do in the associated material set. This restriction has been relaxed.
5252
- Updated `conduit::blueprint::o2mrelation::O2MIndex` such that the number of "ones" in the one-to-many relationship is precomputed when the object is created. The number of "ones" is computed by using the `size()` method from an `O2MIndex`. If an `O2MIndex` is created but `sizes`, `offsets`, and `indices` are not present, then the `O2MIndex` constructor will examine the provided `Node` and search for data arrays to determine the number of "ones". If all data arrays in the provided `Node` have the same number of elements, then that number is assumed to be the number of "ones". If there is disagreement or there are no data arrays present, then the `O2MIndex` throws an error, as the number of "ones" is ambiguous or unknowable.
5353
- Renamed `conduit::blueprint::mesh::matset::count_zones_from_matset()` to `conduit::blueprint::mesh::matset::count_elements_from_matset()`.
54+
- Added error checking for mixed vector fields (fields with `matset_values` defined on vector components). `conduit::blueprint::mesh::field::to_multi_buffer_by_element()`, `conduit::blueprint::mesh::field::to_multi_buffer_by_material()`, `conduit::blueprint::mesh::field::to_uni_buffer_by_element()`, and `conduit::blueprint::mesh::field::to_silo()` now error in this case.
5455
- TODO note about to_silo
5556

5657
#### Relay

src/libs/blueprint/conduit_blueprint_mesh_matset_xforms.cpp

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,102 @@ create_species_names(const conduit::Node &specset,
557557
}
558558
}
559559

560+
//-------------------------------------------------------------------------
561+
// returns true if we are in this case:
562+
// (multi-buffer case where vector components are first class)
563+
// field:
564+
// topology: "topo"
565+
// association: "element"
566+
// values:
567+
// a: [1,2,5,4,4,5,8,6]
568+
// b: [1,2,5,4,4,5,8,6]
569+
// ...
570+
// matset: "mset"
571+
// matset_values:
572+
// a:
573+
// mat1: [1,1,234,32,4545,...]
574+
// mat2: [1,1,234,32,4545,...]
575+
// b:
576+
// mat1: [1,1,234,32,4545,...]
577+
// mat2: [1,1,234,32,4545,...]
578+
// ...
579+
// OR
580+
// (multi-buffer case where materials are first class)
581+
// field:
582+
// topology: "topo"
583+
// association: "element"
584+
// values:
585+
// a: [1,2,5,4,4,5,8,6]
586+
// b: [1,2,5,4,4,5,8,6]
587+
// ...
588+
// matset: "mset"
589+
// matset_values:
590+
// mat1:
591+
// a: [1,1,234,32,4545,...]
592+
// b: [1,1,234,32,4545,...]
593+
// ...
594+
// mat2:
595+
// a: [1,1,234,32,4545,...]
596+
// b: [1,1,234,32,4545,...]
597+
// ...
598+
// OR
599+
// (uni-buffer case with vector components)
600+
// field:
601+
// topology: "topo"
602+
// association: "element"
603+
// values:
604+
// a: [1,2,5,4,4,5,8,6]
605+
// b: [1,2,5,4,4,5,8,6]
606+
// ...
607+
// matset: "mset"
608+
// matset_values:
609+
// a: [1,1,234,32,4545,...]
610+
// b: [1,1,234,32,4545,...]
611+
// ...
612+
bool
613+
detect_mixed_vector_field(const conduit::Node &matset,
614+
const conduit::Node &field)
615+
{
616+
// extra seat belt here
617+
if (! matset.dtype().is_object())
618+
{
619+
CONDUIT_ERROR("blueprint::mesh::field::detect_mixed_vector_field"
620+
" passed matset node must be a valid matset tree.");
621+
}
622+
623+
if (! field.dtype().is_object())
624+
{
625+
CONDUIT_ERROR("blueprint::mesh::field::detect_mixed_vector_field"
626+
" passed field node must be a valid field tree.");
627+
}
628+
629+
// if this field is NOT material dependent
630+
if (! field.has_child("matset_values"))
631+
{
632+
return false;
633+
}
634+
635+
if (conduit::blueprint::mesh::matset::is_multi_buffer(matset))
636+
{
637+
if (field["matset_values"].number_of_children() > 0)
638+
{
639+
// it should be sufficient to check the first child
640+
if (field["matset_values"].child(0).dtype().is_object())
641+
{
642+
return true;
643+
}
644+
}
645+
}
646+
else // uni-buffer
647+
{
648+
if (field["matset_values"].dtype().is_object())
649+
{
650+
return true;
651+
}
652+
}
653+
return false;
654+
}
655+
560656
//-----------------------------------------------------------------------------
561657
void
562658
store_material_data_for_elem_to_silo_arrays(
@@ -3049,6 +3145,13 @@ to_silo(const conduit::Node &field,
30493145
" must be a valid matset tree.");
30503146
}
30513147

3148+
if (conduit::blueprint::mesh::matset::detail::detect_mixed_vector_field(matset, field))
3149+
{
3150+
CONDUIT_ERROR("blueprint::mesh::field::to_silo"
3151+
" Mixed (material-based) field with vector components is unsupported."
3152+
" Please contact a Conduit developer.");
3153+
}
3154+
30523155
conduit::Node specset;
30533156

30543157
conduit::blueprint::mesh::matset::detail::to_silo(matset,
@@ -3088,6 +3191,13 @@ to_multi_buffer_by_element(const conduit::Node &src_matset,
30883191
return;
30893192
}
30903193

3194+
if (conduit::blueprint::mesh::matset::detail::detect_mixed_vector_field(src_matset, src_field))
3195+
{
3196+
CONDUIT_ERROR("blueprint::mesh::field::to_multi_buffer_by_element"
3197+
" Mixed (material-based) field with vector components is unsupported."
3198+
" Please contact a Conduit developer.");
3199+
}
3200+
30913201
dest_field.reset();
30923202
conduit::blueprint::mesh::matset::detail::copy_matset_independent_parts_of_field(
30933203
src_field,
@@ -3162,6 +3272,13 @@ to_uni_buffer_by_element(const conduit::Node &src_matset,
31623272
return;
31633273
}
31643274

3275+
if (conduit::blueprint::mesh::matset::detail::detect_mixed_vector_field(src_matset, src_field))
3276+
{
3277+
CONDUIT_ERROR("blueprint::mesh::field::to_uni_buffer_by_element"
3278+
" Mixed (material-based) field with vector components is unsupported."
3279+
" Please contact a Conduit developer.");
3280+
}
3281+
31653282
dest_field.reset();
31663283
conduit::blueprint::mesh::matset::detail::copy_matset_independent_parts_of_field(
31673284
src_field,
@@ -3236,6 +3353,13 @@ to_multi_buffer_by_material(const conduit::Node &src_matset,
32363353
return;
32373354
}
32383355

3356+
if (conduit::blueprint::mesh::matset::detail::detect_mixed_vector_field(src_matset, src_field))
3357+
{
3358+
CONDUIT_ERROR("blueprint::mesh::field::to_multi_buffer_by_material"
3359+
" Mixed (material-based) field with vector components is unsupported."
3360+
" Please contact a Conduit developer.");
3361+
}
3362+
32393363
dest_field.reset();
32403364
conduit::blueprint::mesh::matset::detail::copy_matset_independent_parts_of_field(
32413365
src_field,

src/tests/blueprint/t_blueprint_mesh_matset_xforms.cpp

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,124 @@ TEST(conduit_blueprint_mesh_matset_xforms, mesh_util_renumber_mat_ids)
12531253
}
12541254
}
12551255

1256+
//-----------------------------------------------------------------------------
1257+
TEST(conduit_blueprint_mesh_matset_xforms, mixed_field_vector_error)
1258+
{
1259+
// multi-buffer case
1260+
{
1261+
Node matset, field;
1262+
const std::string yaml_text1 =
1263+
"topology: \"topo\"\n"
1264+
"volume_fractions: \n"
1265+
" background: [1.0, 1.0, 1.0, 0.0]\n"
1266+
" circle_a: [0.0, 0.0, 0.0, 0.333333333333333]\n"
1267+
" circle_b: [0.0, 0.0, 0.0, 0.333333333333333]\n"
1268+
" circle_c: [0.0, 0.0, 0.0, 0.333333333333333]\n";
1269+
matset.parse(yaml_text1, "yaml");
1270+
1271+
const std::string yaml_text2 =
1272+
"association: \"element\"\n"
1273+
"topology: \"topo\"\n"
1274+
"matset: \"matset\"\n"
1275+
"values:\n"
1276+
" a: [0.0, 0.5, 0.5, 0.300000009437402]\n"
1277+
" b: [0.0, 0.5, 0.5, 0.300000009437402]\n"
1278+
"matset_values: \n"
1279+
" a:\n"
1280+
" background: [0.0, 0.5, 0.5, 0.0]\n"
1281+
" circle_a: [0.0, 0.0, 0.0, 0.100000001490116]\n"
1282+
" circle_b: [0.0, 0.0, 0.0, 0.200000002980232]\n"
1283+
" circle_c: [0.0, 0.0, 0.0, 0.600000023841858]\n"
1284+
" b:\n"
1285+
" background: [0.0, 0.5, 0.5, 0.0]\n"
1286+
" circle_a: [0.0, 0.0, 0.0, 0.100000001490116]\n"
1287+
" circle_b: [0.0, 0.0, 0.0, 0.200000002980232]\n"
1288+
" circle_c: [0.0, 0.0, 0.0, 0.600000023841858]\n";
1289+
field.parse(yaml_text2, "yaml");
1290+
1291+
Node converted_field, matset_silo;
1292+
const std::string converted_matset_name = "matset2";
1293+
1294+
EXPECT_THROW(blueprint::mesh::field::to_multi_buffer_by_element(matset,
1295+
field,
1296+
converted_matset_name,
1297+
converted_field),
1298+
conduit::Error);
1299+
1300+
EXPECT_THROW(blueprint::mesh::field::to_multi_buffer_by_material(matset,
1301+
field,
1302+
converted_matset_name,
1303+
converted_field),
1304+
conduit::Error);
1305+
1306+
EXPECT_THROW(blueprint::mesh::field::to_uni_buffer_by_element(matset,
1307+
field,
1308+
converted_matset_name,
1309+
converted_field),
1310+
conduit::Error);
1311+
1312+
EXPECT_THROW(blueprint::mesh::field::to_silo(field,
1313+
matset,
1314+
matset_silo),
1315+
conduit::Error);
1316+
}
1317+
1318+
// uni-buffer case
1319+
{
1320+
Node matset, field;
1321+
const std::string yaml_text1 =
1322+
"topology: \"topo\"\n"
1323+
"material_map: \n"
1324+
" circle_a: 1\n"
1325+
" circle_b: 2\n"
1326+
" circle_c: 3\n"
1327+
" background: 0\n"
1328+
"volume_fractions: [1.0, 1.0, 1.0, 0.333333333333333, 0.333333333333333, 0.333333333333333]\n"
1329+
"material_ids: [0, 0, 0, 1, 2, 3]\n"
1330+
"sizes: [1, 1, 1, 3]\n"
1331+
"offsets: [0, 1, 2, 3]\n";
1332+
matset.parse(yaml_text1, "yaml");
1333+
1334+
const std::string yaml_text2 =
1335+
"association: \"element\"\n"
1336+
"topology: \"topo\"\n"
1337+
"matset: \"matset\"\n"
1338+
"values:\n"
1339+
" a: [0.0, 0.5, 0.5, 0.300000009437402]\n"
1340+
" b: [0.0, 0.5, 0.5, 0.300000009437402]\n"
1341+
"matset_values:\n"
1342+
" a: [0.0, 0.5, 0.5, 0.100000001490116, 0.200000002980232, 0.600000023841858]\n"
1343+
" b: [0.0, 0.5, 0.5, 0.100000001490116, 0.200000002980232, 0.600000023841858]\n";
1344+
field.parse(yaml_text2, "yaml");
1345+
1346+
Node converted_field, matset_silo;
1347+
const std::string converted_matset_name = "matset2";
1348+
1349+
EXPECT_THROW(blueprint::mesh::field::to_multi_buffer_by_element(matset,
1350+
field,
1351+
converted_matset_name,
1352+
converted_field),
1353+
conduit::Error);
1354+
1355+
EXPECT_THROW(blueprint::mesh::field::to_multi_buffer_by_material(matset,
1356+
field,
1357+
converted_matset_name,
1358+
converted_field),
1359+
conduit::Error);
1360+
1361+
EXPECT_THROW(blueprint::mesh::field::to_uni_buffer_by_element(matset,
1362+
field,
1363+
converted_matset_name,
1364+
converted_field),
1365+
conduit::Error);
1366+
1367+
EXPECT_THROW(blueprint::mesh::field::to_silo(field,
1368+
matset,
1369+
matset_silo),
1370+
conduit::Error);
1371+
}
1372+
}
1373+
12561374
//-----------------------------------------------------------------------------
12571375
TEST(conduit_blueprint_mesh_matset_xforms, mesh_util_venn_to_silo_speed_test)
12581376
{

0 commit comments

Comments
 (0)