Skip to content

Commit

Permalink
I thgink I did it
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinPrivitera committed Jan 10, 2025
1 parent 9e2cb4a commit 9cae5eb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 57 deletions.
59 changes: 30 additions & 29 deletions src/libs/blueprint/conduit_blueprint_mesh_matset_xforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1748,36 +1748,17 @@ to_silo(const conduit::Node &specset,
return sum;
}();

// WARNING: this can produce indices that are out of bounds in specific cases:
// example:
// nmatspec: [0, 2, 2, 0]
// specnames:
// - "a_spec1"
// - "a_spec2"
// - "b_spec1"
// - "b_spec2"
// speclist: [1, 5, 9, -1]
// nmat: 4
// nspecies_mf: 16
// species_mf: [0.0, 1.0, 0.0, 1.0, 0.5, 0.5, 0.0, 1.0, 0.0, 1.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]
// mix_spec: [13, 15, 17]
// mixlen: 3

// mix_spec has 17 at the end of the list. 17 is out of bounds for species_mf. But 17 is
// the correct index given our method of calculation. The third entry in the mix_spec
// array corresponds to a material circle_c which is present in the zone but has no
// species. If circle_c had species, then 17 would be the right index for it.
// I don't think downstream silo data consumers will read


// we save the final index for this zone
return outer_index + local_index;

// TODO return a zero here if the material in the zone contains only 1 species.
// This is a further optimization. It doesn't matter for now since we are
// treating our output like we have all species and all materials in all zones.
// I think the point of this optimization is to also leave stuff out of the
// species_mf array. If I want to do this then I should explore that as well.
// This can produce an out of bounds index in very specific cases.
// If a material has no species, the index produced by this function is
// useless, but downstream data consumers shouldn't be reading the index
// anyway. If a material has no species and it is the last one in the
// material map and the final zone is mixed and contains that material,
// then we can get an index that is out of bounds. This is ok because
// downstream tools like VisIt read based on the number of species, so
// even though the index is garbage it goes unused.
};

dest["speclist"].set(DataType::int64(num_zones));
Expand All @@ -1796,7 +1777,17 @@ to_silo(const conduit::Node &specset,
// I can use the material number to determine which part of the speclist to index into
const int &matno = matlist_entry;
const int mat_index = mat_id_to_array_index[matno];
speclist[zone_id] = calculate_species_index(zone_id, mat_index);
if (nmatspec[mat_index] == 1)
{
// This is an optimization for if the material has only one
// species. See MIR.C in VisIt in the MIR::SpeciesSelect()
// function to see how this optimization is used.
speclist[zone_id] = 0;
}
else
{
speclist[zone_id] = calculate_species_index(zone_id, mat_index);
}
}
else
{
Expand All @@ -1821,7 +1812,17 @@ to_silo(const conduit::Node &specset,
// I can use the material number to determine which part of the speclist to index into
const int matno = silo_mix_mat[mix_id];
const int mat_index = mat_id_to_array_index[matno];
mix_spec.push_back(calculate_species_index(zone_id, mat_index));
if (nmatspec[mat_index] == 1)
{
// This is an optimization for if the material has only one
// species. See MIR.C in VisIt in the MIR::SpeciesSelect()
// function to see how this optimization is used.
mix_spec.push_back(0);
}
else
{
mix_spec.push_back(calculate_species_index(zone_id, mat_index));
}

// since mix_id is a 1-index, we must subtract one
// this makes sure that mix_id = 0 is the last case,
Expand Down
51 changes: 23 additions & 28 deletions src/tests/blueprint/t_blueprint_mesh_matset_xforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,8 @@ TEST(conduit_blueprint_mesh_matset_xforms, mesh_util_to_silo_specset_missing_mat
const Node &matset = mesh["matsets/matset"];
const Node &specset = mesh["specsets/specset"];

Node silo_rep, silo_rep_matset;
Node silo_rep;

// first test transforming specset to silo rep with a regular matset
blueprint::mesh::specset::to_silo(specset, matset, silo_rep);

std::cout << specset.to_yaml() << std::endl;
Expand Down Expand Up @@ -696,9 +695,8 @@ TEST(conduit_blueprint_mesh_matset_xforms, mesh_util_to_silo_specset_missing_mat
const Node &matset = mesh["matsets/matset"];
const Node &specset = mesh["specsets/specset"];

Node silo_rep, silo_rep_matset;
Node silo_rep;

// first test transforming specset to silo rep with a regular matset
blueprint::mesh::specset::to_silo(specset, matset, silo_rep);

std::cout << specset.to_yaml() << std::endl;
Expand All @@ -715,7 +713,7 @@ TEST(conduit_blueprint_mesh_matset_xforms, mesh_util_to_silo_specset_missing_mat
" - \"c_spec1\"\n"
" - \"c_spec2\"\n"
" - \"c_spec3\"\n"
"speclist: [1, 9, 17, -1]\n"
"speclist: [0, 0, 0, -1]\n"
"nmat: 4\n"
"nspecies_mf: 32\n"
"species_mf: [1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.5, 0.0, 1.0, 0.75, 0.1875, 0.0625, 1.0, 0.0, 1.0, 0.5, 0.5, 0.75, 0.1875, 0.0625, 1.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.375, 0.125]\n"
Expand Down Expand Up @@ -749,9 +747,8 @@ TEST(conduit_blueprint_mesh_matset_xforms, mesh_util_to_silo_specset_missing_mat
const Node &matset = mesh["matsets/matset"];
const Node &specset = mesh["specsets/specset"];

Node silo_rep, silo_rep_matset;
Node silo_rep;

// first test transforming specset to silo rep with a regular matset
blueprint::mesh::specset::to_silo(specset, matset, silo_rep);

std::cout << specset.to_yaml() << std::endl;
Expand All @@ -768,7 +765,7 @@ TEST(conduit_blueprint_mesh_matset_xforms, mesh_util_to_silo_specset_missing_mat
" - \"b_spec2\"\n"
" - \"a_spec1\"\n"
" - \"a_spec2\"\n"
"speclist: [4, 12, 20, -1]\n"
"speclist: [0, 0, 0, -1]\n"
"nmat: 4\n"
"nspecies_mf: 32\n"
"species_mf: [1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.75, 0.1875, 0.0625, 1.0, 0.0, 1.0, 0.5, 0.5, 0.75, 0.1875, 0.0625, 1.0, 0.5, 0.5, 0.0, 1.0, 0.5, 0.375, 0.125, 1.0, 0.5, 0.5, 0.5, 0.5]\n"
Expand Down Expand Up @@ -801,31 +798,29 @@ TEST(conduit_blueprint_mesh_matset_xforms, mesh_util_to_silo_specset_missing_mat
const Node &matset = mesh["matsets/matset"];
const Node &specset = mesh["specsets/specset"];

Node silo_rep, silo_rep_matset;
Node silo_rep;

// first test transforming specset to silo rep with a regular matset
blueprint::mesh::specset::to_silo(specset, matset, silo_rep);

std::cout << specset.to_yaml() << std::endl;
std::cout << silo_rep.to_yaml() << std::endl;

// const std::string yaml_text =
// "nmatspec: [0, 2, 0, 3]\n"
// "specnames: \n"
// "- \"a_spec1\"\n"
// "- \"a_spec2\"\n"
// "- \"c_spec1\"\n"
// "- \"c_spec2\"\n"
// "- \"c_spec3\"\n"
// "speclist: [1, 6, 11, -1]\n"
// "nmat: 4\n"
// "nspecies_mf: 20\n"
// "species_mf: [0.0, 1.0, 1.0, 0.0, 0.0, 0.5, 0.5, 0.75, 0.1875, 0.0625, 0.0, 1.0, 0.75, 0.1875, 0.0625, 0.5, 0.5, 0.5, 0.375, 0.125]\n"
// "mix_spec: [16, 18, 18]\n"
// "mixlen: 3\n";
// Node baseline;
// baseline.parse(yaml_text, "yaml");

// EXPECT_FALSE(silo_rep.diff(baseline, info, CONDUIT_EPSILON, true));
const std::string yaml_text =
"nmatspec: [0, 2, 2, 0]\n"
"specnames: \n"
" - \"a_spec1\"\n"
" - \"a_spec2\"\n"
" - \"b_spec1\"\n"
" - \"b_spec2\"\n"
"speclist: [1, 5, 9, -1]\n"
"nmat: 4\n"
"nspecies_mf: 16\n"
"species_mf: [0.0, 1.0, 0.0, 1.0, 0.5, 0.5, 0.0, 1.0, 0.0, 1.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]\n"
"mix_spec: [13, 15, 17]\n"
"mixlen: 3\n";
Node baseline;
baseline.parse(yaml_text, "yaml");

EXPECT_FALSE(silo_rep.diff(baseline, info, CONDUIT_EPSILON, true));
}
}

0 comments on commit 9cae5eb

Please sign in to comment.