Skip to content

Commit eae911b

Browse files
Matset Accessor: Add mat_order_id (#1544)
1 parent 54afe50 commit eae911b

3 files changed

Lines changed: 170 additions & 16 deletions

File tree

src/libs/blueprint/conduit_blueprint_mesh_matset_accessor.cpp

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ namespace matset
5252
//---------------------------------------------------------------------------//
5353
MatsetAccessor::MatsetAccessor()
5454
: m_get_mat_id(&MatsetAccessor::get_error_mat_id),
55+
m_get_mat_order_id(&MatsetAccessor::get_error_mat_order_id),
5556
m_get_elem_id(&MatsetAccessor::get_error_elem_id),
5657
m_get_vol_frac(&MatsetAccessor::get_error_vol_frac),
5758
m_get_mset_val(&MatsetAccessor::get_error_mset_val),
@@ -66,6 +67,7 @@ MatsetAccessor::MatsetAccessor()
6667
//---------------------------------------------------------------------------//
6768
MatsetAccessor::MatsetAccessor(const Node &matset)
6869
: m_get_mat_id(&MatsetAccessor::get_error_mat_id),
70+
m_get_mat_order_id(&MatsetAccessor::get_error_mat_order_id),
6971
m_get_elem_id(&MatsetAccessor::get_error_elem_id),
7072
m_get_vol_frac(&MatsetAccessor::get_error_vol_frac),
7173
m_get_mset_val(&MatsetAccessor::get_error_mset_val),
@@ -81,6 +83,7 @@ MatsetAccessor::MatsetAccessor(const Node &matset)
8183
MatsetAccessor::MatsetAccessor(const Node &matset,
8284
const Node &specset_or_field)
8385
: m_get_mat_id(&MatsetAccessor::get_error_mat_id),
86+
m_get_mat_order_id(&MatsetAccessor::get_error_mat_order_id),
8487
m_get_elem_id(&MatsetAccessor::get_error_elem_id),
8588
m_get_vol_frac(&MatsetAccessor::get_error_vol_frac),
8689
m_get_mset_val(&MatsetAccessor::get_error_mset_val),
@@ -108,6 +111,7 @@ MatsetAccessor::MatsetAccessor(const Node &matset,
108111
const Node &field,
109112
const Node &specset)
110113
: m_get_mat_id(&MatsetAccessor::get_error_mat_id),
114+
m_get_mat_order_id(&MatsetAccessor::get_error_mat_order_id),
111115
m_get_elem_id(&MatsetAccessor::get_error_elem_id),
112116
m_get_vol_frac(&MatsetAccessor::get_error_vol_frac),
113117
m_get_mset_val(&MatsetAccessor::get_error_mset_val),
@@ -122,6 +126,7 @@ MatsetAccessor::MatsetAccessor(const Node &matset,
122126
//---------------------------------------------------------------------------//
123127
MatsetAccessor::MatsetAccessor(const MatsetAccessor &m_acc)
124128
: m_get_mat_id(m_acc.m_get_mat_id),
129+
m_get_mat_order_id(m_acc.m_get_mat_order_id),
125130
m_get_elem_id(m_acc.m_get_elem_id),
126131
m_get_vol_frac(m_acc.m_get_vol_frac),
127132
m_get_mset_val(m_acc.m_get_mset_val),
@@ -145,6 +150,8 @@ MatsetAccessor::MatsetAccessor(const MatsetAccessor &m_acc)
145150
m_multi_mass_fracs(m_acc.m_multi_mass_fracs),
146151
m_sbm_elem_ids(m_acc.m_sbm_elem_ids),
147152
m_sbe_material_ids(m_acc.m_sbe_material_ids),
153+
m_sbe_mat_order_ids(m_acc.m_sbe_mat_order_ids),
154+
m_sbe_mat_order_ids_acc(m_acc.m_sbe_mat_order_ids_acc),
148155
m_sbe_vol_fracs(m_acc.m_sbe_vol_fracs),
149156
m_sbe_mset_vals(m_acc.m_sbe_mset_vals),
150157
m_sbe_o2m_idx(m_acc.m_sbe_o2m_idx),
@@ -159,6 +166,7 @@ MatsetAccessor::operator=(const MatsetAccessor &m_acc)
159166
if (this != &m_acc)
160167
{
161168
m_get_mat_id = m_acc.m_get_mat_id;
169+
m_get_mat_order_id = m_acc.m_get_mat_order_id;
162170
m_get_elem_id = m_acc.m_get_elem_id;
163171
m_get_vol_frac = m_acc.m_get_vol_frac;
164172
m_get_mset_val = m_acc.m_get_mset_val;
@@ -182,6 +190,8 @@ MatsetAccessor::operator=(const MatsetAccessor &m_acc)
182190
m_multi_mass_fracs = m_acc.m_multi_mass_fracs;
183191
m_sbm_elem_ids = m_acc.m_sbm_elem_ids;
184192
m_sbe_material_ids = m_acc.m_sbe_material_ids;
193+
m_sbe_mat_order_ids = m_acc.m_sbe_mat_order_ids;
194+
m_sbe_mat_order_ids_acc = m_acc.m_sbe_mat_order_ids_acc;
185195
m_sbe_vol_fracs = m_acc.m_sbe_vol_fracs;
186196
m_sbe_mset_vals = m_acc.m_sbe_mset_vals;
187197
m_sbe_o2m_idx = m_acc.m_sbe_o2m_idx;
@@ -227,8 +237,8 @@ MatsetAccessor::init(const Node &matset,
227237
m_has_specset = true;
228238
}
229239

230-
m_is_uni_buffer = blueprint::mesh::matset::is_uni_buffer(matset);
231-
m_is_element_dominant = blueprint::mesh::matset::is_element_dominant(matset);
240+
m_is_uni_buffer = matset::is_uni_buffer(matset);
241+
m_is_element_dominant = matset::is_element_dominant(matset);
232242

233243
m_num_elems = count_zones_from_matset(matset);
234244
m_num_mats = count_materials_from_matset(matset);
@@ -245,6 +255,28 @@ MatsetAccessor::init(const Node &matset,
245255
m_sbe_material_ids = matset["material_ids"].value();
246256
m_sbe_vol_fracs = matset["volume_fractions"].value();
247257
m_sbe_o2m_idx = o2mrelation::O2MIndex(matset);
258+
259+
//
260+
// save material order ids
261+
//
262+
const index_t num_vol_fracs = matset["volume_fractions"].dtype().number_of_elements();
263+
m_sbe_mat_order_ids.set(DataType::index_t(num_vol_fracs));
264+
m_sbe_mat_order_ids_acc = m_sbe_mat_order_ids.value();
265+
// create a map from material id to material order id
266+
std::map<index_t, index_t> mat_id_to_order_id;
267+
for (index_t mat_idx = 0; mat_idx < m_num_mats; mat_idx ++)
268+
{
269+
const index_t mat_id = material_map.child(mat_idx).to_index_t();
270+
mat_id_to_order_id[mat_id] = mat_idx;
271+
}
272+
// now we can fill the mat order id array using the information we've collected
273+
for (index_t vf_elem = 0; vf_elem < num_vol_fracs; vf_elem ++)
274+
{
275+
const index_t mat_id = m_sbe_material_ids[vf_elem];
276+
const index_t mat_order_id = mat_id_to_order_id.at(mat_id);
277+
m_sbe_mat_order_ids_acc.set(vf_elem, mat_order_id);
278+
}
279+
248280
if (nullptr != field)
249281
{
250282
m_sbe_mset_vals = (*field)["matset_values"].value();
@@ -423,7 +455,6 @@ MatsetAccessor::init(const Node &matset,
423455
// We pay a price at the start when creating these arrays, but we enable quick
424456
// access of species mass fraction data.
425457

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

467498
// set our fetch methods
468-
m_get_mat_id = &MatsetAccessor::get_sbe_mat_id;
469-
m_get_elem_id = &MatsetAccessor::get_sbe_elem_id;
470-
m_get_vol_frac = &MatsetAccessor::get_sbe_vol_frac;
499+
m_get_mat_id = &MatsetAccessor::get_sbe_mat_id;
500+
m_get_mat_order_id = &MatsetAccessor::get_sbe_mat_order_id;
501+
m_get_elem_id = &MatsetAccessor::get_sbe_elem_id;
502+
m_get_vol_frac = &MatsetAccessor::get_sbe_vol_frac;
471503
if (nullptr != field)
472504
{
473505
m_get_mset_val = &MatsetAccessor::get_sbe_mset_val;
@@ -571,9 +603,10 @@ MatsetAccessor::init(const Node &matset,
571603
// multi-buffer by element (full)
572604
if (m_is_element_dominant)
573605
{
574-
m_get_mat_id = &MatsetAccessor::get_full_mat_id;
575-
m_get_elem_id = &MatsetAccessor::get_full_elem_id;
576-
m_get_vol_frac = &MatsetAccessor::get_full_vol_frac;
606+
m_get_mat_id = &MatsetAccessor::get_full_mat_id;
607+
m_get_mat_order_id = &MatsetAccessor::get_full_mat_order_id;
608+
m_get_elem_id = &MatsetAccessor::get_full_elem_id;
609+
m_get_vol_frac = &MatsetAccessor::get_full_vol_frac;
577610
if (nullptr != field)
578611
{
579612
m_get_mset_val = &MatsetAccessor::get_full_mset_val;
@@ -593,9 +626,10 @@ MatsetAccessor::init(const Node &matset,
593626
m_sbm_elem_ids.push_back(matset["element_ids"][matname].value());
594627
}
595628

596-
m_get_mat_id = &MatsetAccessor::get_sbm_mat_id;
597-
m_get_elem_id = &MatsetAccessor::get_sbm_elem_id;
598-
m_get_vol_frac = &MatsetAccessor::get_sbm_vol_frac;
629+
m_get_mat_id = &MatsetAccessor::get_sbm_mat_id;
630+
m_get_mat_order_id = &MatsetAccessor::get_sbm_mat_order_id;
631+
m_get_elem_id = &MatsetAccessor::get_sbm_elem_id;
632+
m_get_vol_frac = &MatsetAccessor::get_sbm_vol_frac;
599633
if (nullptr != field)
600634
{
601635
m_get_mset_val = &MatsetAccessor::get_sbm_mset_val;
@@ -623,6 +657,14 @@ MatsetAccessor::get_full_mat_id(const index_t elem_idx, const index_t mat_idx) c
623657
return m_multi_mat_idx_map_acc[mat_idx];
624658
}
625659

660+
//-----------------------------------------------------------------------------
661+
index_t
662+
MatsetAccessor::get_full_mat_order_id(const index_t elem_idx, const index_t mat_idx) const
663+
{
664+
(void) elem_idx;
665+
return mat_idx;
666+
}
667+
626668
//-----------------------------------------------------------------------------
627669
index_t
628670
MatsetAccessor::get_full_elem_id(const index_t elem_idx, const index_t mat_idx) const
@@ -676,6 +718,14 @@ MatsetAccessor::get_sbm_mat_id(const index_t elem_idx, const index_t mat_idx) co
676718
return m_multi_mat_idx_map_acc[mat_idx];
677719
}
678720

721+
//-----------------------------------------------------------------------------
722+
index_t
723+
MatsetAccessor::get_sbm_mat_order_id(const index_t elem_idx, const index_t mat_idx) const
724+
{
725+
(void) elem_idx;
726+
return mat_idx;
727+
}
728+
679729
//-----------------------------------------------------------------------------
680730
index_t
681731
MatsetAccessor::get_sbm_elem_id(const index_t elem_idx, const index_t mat_idx) const
@@ -735,6 +785,14 @@ MatsetAccessor::get_sbe_mat_id(const index_t elem_idx, const index_t mat_idx) co
735785
return m_sbe_material_ids[data_index];
736786
}
737787

788+
//-----------------------------------------------------------------------------
789+
index_t
790+
MatsetAccessor::get_sbe_mat_order_id(const index_t elem_idx, const index_t mat_idx) const
791+
{
792+
const index_t data_index = m_sbe_o2m_idx.index(elem_idx, mat_idx);
793+
return m_sbe_mat_order_ids_acc[data_index];
794+
}
795+
738796
//-----------------------------------------------------------------------------
739797
index_t
740798
MatsetAccessor::get_sbe_elem_id(const index_t elem_idx, const index_t mat_idx) const
@@ -814,6 +872,16 @@ MatsetAccessor::get_error_mat_id(const index_t elem_idx, const index_t mat_idx)
814872
return 0;
815873
}
816874

875+
//-----------------------------------------------------------------------------
876+
index_t
877+
MatsetAccessor::get_error_mat_order_id(const index_t elem_idx, const index_t mat_idx) const
878+
{
879+
(void) elem_idx;
880+
(void) mat_idx;
881+
CONDUIT_ERROR("Impossible to fetch mat_order_id from material set.");
882+
return 0;
883+
}
884+
817885
//-----------------------------------------------------------------------------
818886
index_t
819887
MatsetAccessor::get_error_elem_id(const index_t elem_idx, const index_t mat_idx) const
@@ -921,4 +989,3 @@ MatsetAccessor::get_error_nspec_for_mat(const index_t elem_idx, const index_t ma
921989
// -- end conduit:: --
922990
//-----------------------------------------------------------------------------
923991

924-

src/libs/blueprint/conduit_blueprint_mesh_matset_accessor.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class CONDUIT_BLUEPRINT_API MatsetAccessor
7070
/// MatsetAccessor Function pointer types
7171
//-----------------------------------------------------------------------------
7272
using GetMatIdPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
73+
using GetMatOrderIdPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
7374
using GetElemIdPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
7475
using GetVolFracPtr = float64 (MatsetAccessor::*)(index_t, index_t) const;
7576
using GetMsetValPtr = float64 (MatsetAccessor::*)(index_t, index_t) const;
@@ -190,6 +191,13 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
190191
return (this->*m_get_mat_id)(elem_idx, mat_idx);
191192
}
192193

194+
inline
195+
index_t get_mat_order_id(const index_t elem_idx,
196+
const index_t mat_idx) const
197+
{
198+
return (this->*m_get_mat_order_id)(elem_idx, mat_idx);
199+
}
200+
193201
inline
194202
index_t get_elem_id(const index_t elem_idx,
195203
const index_t mat_idx) const
@@ -246,6 +254,7 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
246254
// 0 <= mat_idx < num mats
247255
// 0 <= spec_idx < num species for material mat_idx
248256
index_t get_full_mat_id(const index_t elem_idx, const index_t mat_idx) const;
257+
index_t get_full_mat_order_id(const index_t elem_idx, const index_t mat_idx) const;
249258
index_t get_full_elem_id(const index_t elem_idx, const index_t mat_idx) const;
250259
float64 get_full_vol_frac(const index_t elem_idx, const index_t mat_idx) const;
251260
float64 get_full_mset_val(const index_t elem_idx, const index_t mat_idx) const;
@@ -265,6 +274,7 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
265274
// 0 <= mat_idx < num mats
266275
// 0 <= spec_idx < num species for material mat_idx
267276
index_t get_sbm_mat_id(const index_t elem_idx, const index_t mat_idx) const;
277+
index_t get_sbm_mat_order_id(const index_t elem_idx, const index_t mat_idx) const;
268278
index_t get_sbm_elem_id(const index_t elem_idx, const index_t mat_idx) const;
269279
float64 get_sbm_vol_frac(const index_t elem_idx, const index_t mat_idx) const;
270280
float64 get_sbm_mset_val(const index_t elem_idx, const index_t mat_idx) const;
@@ -278,10 +288,11 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
278288
index_t get_sbm_nspec_for_mat(const index_t elem_idx, const index_t mat_idx) const;
279289

280290
// uni-buffer by element (sparse by element)
281-
// 0 <= elem_idx < num element
291+
// 0 <= elem_idx < num elements
282292
// 0 <= mat_idx < num mats for element elem_idx
283293
// 0 <= spec_idx < num species for material mat_idx in element elem_idx
284294
index_t get_sbe_mat_id(const index_t elem_idx, const index_t mat_idx) const;
295+
index_t get_sbe_mat_order_id(const index_t elem_idx, const index_t mat_idx) const;
285296
index_t get_sbe_elem_id(const index_t elem_idx, const index_t mat_idx) const;
286297
float64 get_sbe_vol_frac(const index_t elem_idx, const index_t mat_idx) const;
287298
float64 get_sbe_mset_val(const index_t elem_idx, const index_t mat_idx) const;
@@ -302,6 +313,7 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
302313
// of just a segfault. The field and specset access methods will only be
303314
// turned on if a field or a specset is provided.
304315
index_t get_error_mat_id(const index_t elem_idx, const index_t mat_idx) const;
316+
index_t get_error_mat_order_id(const index_t elem_idx, const index_t mat_idx) const;
305317
index_t get_error_elem_id(const index_t elem_idx, const index_t mat_idx) const;
306318
float64 get_error_vol_frac(const index_t elem_idx, const index_t mat_idx) const;
307319
float64 get_error_mset_val(const index_t elem_idx, const index_t mat_idx) const;
@@ -321,6 +333,7 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
321333
// function pointer members
322334
// these take us to implementations for each layout type
323335
GetMatIdPtr m_get_mat_id;
336+
GetMatOrderIdPtr m_get_mat_order_id;
324337
GetElemIdPtr m_get_elem_id;
325338
GetVolFracPtr m_get_vol_frac;
326339
GetMsetValPtr m_get_mset_val;
@@ -355,6 +368,8 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
355368

356369
// uni-buffer element-dominant (sparse by element) members
357370
index_t_accessor m_sbe_material_ids;
371+
Node m_sbe_mat_order_ids;
372+
index_t_accessor m_sbe_mat_order_ids_acc;
358373
float64_accessor m_sbe_vol_fracs;
359374
float64_accessor m_sbe_mset_vals;
360375
o2mrelation::O2MIndex m_sbe_o2m_idx;
@@ -391,4 +406,4 @@ using GetNMatSpecPtr = index_t (MatsetAccessor::*)(index_t, index_t) const;
391406
//-----------------------------------------------------------------------------
392407

393408

394-
#endif
409+
#endif

0 commit comments

Comments
 (0)