Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 80 additions & 13 deletions src/libs/blueprint/conduit_blueprint_mesh_matset_accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace matset
//---------------------------------------------------------------------------//
MatsetAccessor::MatsetAccessor()
: m_get_mat_id(&MatsetAccessor::get_error_mat_id),
m_get_mat_order_id(&MatsetAccessor::get_error_mat_order_id),
m_get_elem_id(&MatsetAccessor::get_error_elem_id),
m_get_vol_frac(&MatsetAccessor::get_error_vol_frac),
m_get_mset_val(&MatsetAccessor::get_error_mset_val),
Expand All @@ -66,6 +67,7 @@ MatsetAccessor::MatsetAccessor()
//---------------------------------------------------------------------------//
MatsetAccessor::MatsetAccessor(const Node &matset)
: m_get_mat_id(&MatsetAccessor::get_error_mat_id),
m_get_mat_order_id(&MatsetAccessor::get_error_mat_order_id),
m_get_elem_id(&MatsetAccessor::get_error_elem_id),
m_get_vol_frac(&MatsetAccessor::get_error_vol_frac),
m_get_mset_val(&MatsetAccessor::get_error_mset_val),
Expand All @@ -81,6 +83,7 @@ MatsetAccessor::MatsetAccessor(const Node &matset)
MatsetAccessor::MatsetAccessor(const Node &matset,
const Node &specset_or_field)
: m_get_mat_id(&MatsetAccessor::get_error_mat_id),
m_get_mat_order_id(&MatsetAccessor::get_error_mat_order_id),
m_get_elem_id(&MatsetAccessor::get_error_elem_id),
m_get_vol_frac(&MatsetAccessor::get_error_vol_frac),
m_get_mset_val(&MatsetAccessor::get_error_mset_val),
Expand Down Expand Up @@ -108,6 +111,7 @@ MatsetAccessor::MatsetAccessor(const Node &matset,
const Node &field,
const Node &specset)
: m_get_mat_id(&MatsetAccessor::get_error_mat_id),
m_get_mat_order_id(&MatsetAccessor::get_error_mat_order_id),
m_get_elem_id(&MatsetAccessor::get_error_elem_id),
m_get_vol_frac(&MatsetAccessor::get_error_vol_frac),
m_get_mset_val(&MatsetAccessor::get_error_mset_val),
Expand All @@ -122,6 +126,7 @@ MatsetAccessor::MatsetAccessor(const Node &matset,
//---------------------------------------------------------------------------//
MatsetAccessor::MatsetAccessor(const MatsetAccessor &m_acc)
: m_get_mat_id(m_acc.m_get_mat_id),
m_get_mat_order_id(m_acc.m_get_mat_order_id),
m_get_elem_id(m_acc.m_get_elem_id),
m_get_vol_frac(m_acc.m_get_vol_frac),
m_get_mset_val(m_acc.m_get_mset_val),
Expand All @@ -145,6 +150,8 @@ MatsetAccessor::MatsetAccessor(const MatsetAccessor &m_acc)
m_multi_mass_fracs(m_acc.m_multi_mass_fracs),
m_sbm_elem_ids(m_acc.m_sbm_elem_ids),
m_sbe_material_ids(m_acc.m_sbe_material_ids),
m_sbe_mat_order_ids(m_acc.m_sbe_mat_order_ids),
m_sbe_mat_order_ids_acc(m_acc.m_sbe_mat_order_ids_acc),
m_sbe_vol_fracs(m_acc.m_sbe_vol_fracs),
m_sbe_mset_vals(m_acc.m_sbe_mset_vals),
m_sbe_o2m_idx(m_acc.m_sbe_o2m_idx),
Expand All @@ -159,6 +166,7 @@ MatsetAccessor::operator=(const MatsetAccessor &m_acc)
if (this != &m_acc)
{
m_get_mat_id = m_acc.m_get_mat_id;
m_get_mat_order_id = m_acc.m_get_mat_order_id;
m_get_elem_id = m_acc.m_get_elem_id;
m_get_vol_frac = m_acc.m_get_vol_frac;
m_get_mset_val = m_acc.m_get_mset_val;
Expand All @@ -182,6 +190,8 @@ MatsetAccessor::operator=(const MatsetAccessor &m_acc)
m_multi_mass_fracs = m_acc.m_multi_mass_fracs;
m_sbm_elem_ids = m_acc.m_sbm_elem_ids;
m_sbe_material_ids = m_acc.m_sbe_material_ids;
m_sbe_mat_order_ids = m_acc.m_sbe_mat_order_ids;
m_sbe_mat_order_ids_acc = m_acc.m_sbe_mat_order_ids_acc;
m_sbe_vol_fracs = m_acc.m_sbe_vol_fracs;
m_sbe_mset_vals = m_acc.m_sbe_mset_vals;
m_sbe_o2m_idx = m_acc.m_sbe_o2m_idx;
Expand Down Expand Up @@ -227,8 +237,8 @@ MatsetAccessor::init(const Node &matset,
m_has_specset = true;
}

m_is_uni_buffer = blueprint::mesh::matset::is_uni_buffer(matset);
m_is_element_dominant = blueprint::mesh::matset::is_element_dominant(matset);
m_is_uni_buffer = matset::is_uni_buffer(matset);
m_is_element_dominant = matset::is_element_dominant(matset);

m_num_elems = count_zones_from_matset(matset);
m_num_mats = count_materials_from_matset(matset);
Expand All @@ -245,6 +255,28 @@ MatsetAccessor::init(const Node &matset,
m_sbe_material_ids = matset["material_ids"].value();
m_sbe_vol_fracs = matset["volume_fractions"].value();
m_sbe_o2m_idx = o2mrelation::O2MIndex(matset);

//
// save material order ids
//
const index_t num_vol_fracs = matset["volume_fractions"].dtype().number_of_elements();
m_sbe_mat_order_ids.set(DataType::index_t(num_vol_fracs));
m_sbe_mat_order_ids_acc = m_sbe_mat_order_ids.value();
// create a map from material id to material order id
std::map<index_t, index_t> mat_id_to_order_id;
for (index_t mat_idx = 0; mat_idx < m_num_mats; mat_idx ++)
{
const index_t mat_id = material_map.child(mat_idx).to_index_t();
mat_id_to_order_id[mat_id] = mat_idx;
}
// now we can fill the mat order id array using the information we've collected
for (index_t vf_elem = 0; vf_elem < num_vol_fracs; vf_elem ++)
{
const index_t mat_id = m_sbe_material_ids[vf_elem];
const index_t mat_order_id = mat_id_to_order_id.at(mat_id);
m_sbe_mat_order_ids_acc.set(vf_elem, mat_order_id);
}

if (nullptr != field)
{
m_sbe_mset_vals = (*field)["matset_values"].value();
Expand Down Expand Up @@ -423,7 +455,6 @@ MatsetAccessor::init(const Node &matset,
// We pay a price at the start when creating these arrays, but we enable quick
// access of species mass fraction data.

const index_t num_vol_fracs = matset["volume_fractions"].dtype().number_of_elements();
m_nmatspec["nmatspec"].set(DataType::index_t(num_vol_fracs));
m_nmatspec_acc = m_nmatspec["nmatspec"].value();
m_nmatspec["nmatspec_offsets"].set(DataType::index_t(num_vol_fracs));
Expand Down Expand Up @@ -465,9 +496,10 @@ MatsetAccessor::init(const Node &matset,
}

// set our fetch methods
m_get_mat_id = &MatsetAccessor::get_sbe_mat_id;
m_get_elem_id = &MatsetAccessor::get_sbe_elem_id;
m_get_vol_frac = &MatsetAccessor::get_sbe_vol_frac;
m_get_mat_id = &MatsetAccessor::get_sbe_mat_id;
m_get_mat_order_id = &MatsetAccessor::get_sbe_mat_order_id;
m_get_elem_id = &MatsetAccessor::get_sbe_elem_id;
m_get_vol_frac = &MatsetAccessor::get_sbe_vol_frac;
if (nullptr != field)
{
m_get_mset_val = &MatsetAccessor::get_sbe_mset_val;
Expand Down Expand Up @@ -571,9 +603,10 @@ MatsetAccessor::init(const Node &matset,
// multi-buffer by element (full)
if (m_is_element_dominant)
{
m_get_mat_id = &MatsetAccessor::get_full_mat_id;
m_get_elem_id = &MatsetAccessor::get_full_elem_id;
m_get_vol_frac = &MatsetAccessor::get_full_vol_frac;
m_get_mat_id = &MatsetAccessor::get_full_mat_id;
m_get_mat_order_id = &MatsetAccessor::get_full_mat_order_id;
m_get_elem_id = &MatsetAccessor::get_full_elem_id;
m_get_vol_frac = &MatsetAccessor::get_full_vol_frac;
if (nullptr != field)
{
m_get_mset_val = &MatsetAccessor::get_full_mset_val;
Expand All @@ -593,9 +626,10 @@ MatsetAccessor::init(const Node &matset,
m_sbm_elem_ids.push_back(matset["element_ids"][matname].value());
}

m_get_mat_id = &MatsetAccessor::get_sbm_mat_id;
m_get_elem_id = &MatsetAccessor::get_sbm_elem_id;
m_get_vol_frac = &MatsetAccessor::get_sbm_vol_frac;
m_get_mat_id = &MatsetAccessor::get_sbm_mat_id;
m_get_mat_order_id = &MatsetAccessor::get_sbm_mat_order_id;
m_get_elem_id = &MatsetAccessor::get_sbm_elem_id;
m_get_vol_frac = &MatsetAccessor::get_sbm_vol_frac;
if (nullptr != field)
{
m_get_mset_val = &MatsetAccessor::get_sbm_mset_val;
Expand Down Expand Up @@ -623,6 +657,14 @@ MatsetAccessor::get_full_mat_id(const index_t elem_idx, const index_t mat_idx) c
return m_multi_mat_idx_map_acc[mat_idx];
}

//-----------------------------------------------------------------------------
index_t
MatsetAccessor::get_full_mat_order_id(const index_t elem_idx, const index_t mat_idx) const
{
(void) elem_idx;
return mat_idx;
}

//-----------------------------------------------------------------------------
index_t
MatsetAccessor::get_full_elem_id(const index_t elem_idx, const index_t mat_idx) const
Expand Down Expand Up @@ -676,6 +718,14 @@ MatsetAccessor::get_sbm_mat_id(const index_t elem_idx, const index_t mat_idx) co
return m_multi_mat_idx_map_acc[mat_idx];
}

//-----------------------------------------------------------------------------
index_t
MatsetAccessor::get_sbm_mat_order_id(const index_t elem_idx, const index_t mat_idx) const
{
(void) elem_idx;
return mat_idx;
}

//-----------------------------------------------------------------------------
index_t
MatsetAccessor::get_sbm_elem_id(const index_t elem_idx, const index_t mat_idx) const
Expand Down Expand Up @@ -735,6 +785,14 @@ MatsetAccessor::get_sbe_mat_id(const index_t elem_idx, const index_t mat_idx) co
return m_sbe_material_ids[data_index];
}

//-----------------------------------------------------------------------------
index_t
MatsetAccessor::get_sbe_mat_order_id(const index_t elem_idx, const index_t mat_idx) const
{
const index_t data_index = m_sbe_o2m_idx.index(elem_idx, mat_idx);
return m_sbe_mat_order_ids_acc[data_index];
}

//-----------------------------------------------------------------------------
index_t
MatsetAccessor::get_sbe_elem_id(const index_t elem_idx, const index_t mat_idx) const
Expand Down Expand Up @@ -814,6 +872,16 @@ MatsetAccessor::get_error_mat_id(const index_t elem_idx, const index_t mat_idx)
return 0;
}

//-----------------------------------------------------------------------------
index_t
MatsetAccessor::get_error_mat_order_id(const index_t elem_idx, const index_t mat_idx) const
{
(void) elem_idx;
(void) mat_idx;
CONDUIT_ERROR("Impossible to fetch mat_order_id from material set.");
return 0;
}

//-----------------------------------------------------------------------------
index_t
MatsetAccessor::get_error_elem_id(const index_t elem_idx, const index_t mat_idx) const
Expand Down Expand Up @@ -921,4 +989,3 @@ MatsetAccessor::get_error_nspec_for_mat(const index_t elem_idx, const index_t ma
// -- end conduit:: --
//-----------------------------------------------------------------------------


19 changes: 17 additions & 2 deletions src/libs/blueprint/conduit_blueprint_mesh_matset_accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class CONDUIT_BLUEPRINT_API MatsetAccessor
/// MatsetAccessor Function pointer types
//-----------------------------------------------------------------------------
using GetMatIdPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
using GetMatOrderIdPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
using GetElemIdPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
using GetVolFracPtr = float64 (MatsetAccessor::*)(index_t, index_t) const;
using GetMsetValPtr = float64 (MatsetAccessor::*)(index_t, index_t) const;
Expand Down Expand Up @@ -190,6 +191,13 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
return (this->*m_get_mat_id)(elem_idx, mat_idx);
}

inline
index_t get_mat_order_id(const index_t elem_idx,
const index_t mat_idx) const
{
return (this->*m_get_mat_order_id)(elem_idx, mat_idx);
}

inline
index_t get_elem_id(const index_t elem_idx,
const index_t mat_idx) const
Expand Down Expand Up @@ -246,6 +254,7 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
// 0 <= mat_idx < num mats
// 0 <= spec_idx < num species for material mat_idx
index_t get_full_mat_id(const index_t elem_idx, const index_t mat_idx) const;
index_t get_full_mat_order_id(const index_t elem_idx, const index_t mat_idx) const;
index_t get_full_elem_id(const index_t elem_idx, const index_t mat_idx) const;
float64 get_full_vol_frac(const index_t elem_idx, const index_t mat_idx) const;
float64 get_full_mset_val(const index_t elem_idx, const index_t mat_idx) const;
Expand All @@ -265,6 +274,7 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
// 0 <= mat_idx < num mats
// 0 <= spec_idx < num species for material mat_idx
index_t get_sbm_mat_id(const index_t elem_idx, const index_t mat_idx) const;
index_t get_sbm_mat_order_id(const index_t elem_idx, const index_t mat_idx) const;
index_t get_sbm_elem_id(const index_t elem_idx, const index_t mat_idx) const;
float64 get_sbm_vol_frac(const index_t elem_idx, const index_t mat_idx) const;
float64 get_sbm_mset_val(const index_t elem_idx, const index_t mat_idx) const;
Expand All @@ -278,10 +288,11 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
index_t get_sbm_nspec_for_mat(const index_t elem_idx, const index_t mat_idx) const;

// uni-buffer by element (sparse by element)
// 0 <= elem_idx < num element
// 0 <= elem_idx < num elements
// 0 <= mat_idx < num mats for element elem_idx
// 0 <= spec_idx < num species for material mat_idx in element elem_idx
index_t get_sbe_mat_id(const index_t elem_idx, const index_t mat_idx) const;
index_t get_sbe_mat_order_id(const index_t elem_idx, const index_t mat_idx) const;
index_t get_sbe_elem_id(const index_t elem_idx, const index_t mat_idx) const;
float64 get_sbe_vol_frac(const index_t elem_idx, const index_t mat_idx) const;
float64 get_sbe_mset_val(const index_t elem_idx, const index_t mat_idx) const;
Expand All @@ -302,6 +313,7 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
// of just a segfault. The field and specset access methods will only be
// turned on if a field or a specset is provided.
index_t get_error_mat_id(const index_t elem_idx, const index_t mat_idx) const;
index_t get_error_mat_order_id(const index_t elem_idx, const index_t mat_idx) const;
index_t get_error_elem_id(const index_t elem_idx, const index_t mat_idx) const;
float64 get_error_vol_frac(const index_t elem_idx, const index_t mat_idx) const;
float64 get_error_mset_val(const index_t elem_idx, const index_t mat_idx) const;
Expand All @@ -321,6 +333,7 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
// function pointer members
// these take us to implementations for each layout type
GetMatIdPtr m_get_mat_id;
GetMatOrderIdPtr m_get_mat_order_id;
GetElemIdPtr m_get_elem_id;
GetVolFracPtr m_get_vol_frac;
GetMsetValPtr m_get_mset_val;
Expand Down Expand Up @@ -355,6 +368,8 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;

// uni-buffer element-dominant (sparse by element) members
index_t_accessor m_sbe_material_ids;
Node m_sbe_mat_order_ids;
index_t_accessor m_sbe_mat_order_ids_acc;
float64_accessor m_sbe_vol_fracs;
float64_accessor m_sbe_mset_vals;
o2mrelation::O2MIndex m_sbe_o2m_idx;
Expand Down Expand Up @@ -391,4 +406,4 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
//-----------------------------------------------------------------------------


#endif
#endif
Loading
Loading