Skip to content

Commit

Permalink
Refactor of translation from mesh handle to index for DAGMC geometry. (
Browse files Browse the repository at this point in the history
  • Loading branch information
pshriwise authored Sep 14, 2023
1 parent c8c5afa commit ccb76b3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
19 changes: 17 additions & 2 deletions include/openmc/dagmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class DAGSurface : public Surface {
public:
DAGSurface(std::shared_ptr<moab::DagMC> dag_ptr, int32_t dag_idx);

moab::EntityHandle mesh_handle() const;

double evaluate(Position r) const override;
double distance(Position r, Direction u, bool coincident) const override;
Direction normal(Position r) const override;
Expand All @@ -45,7 +47,7 @@ class DAGSurface : public Surface {
inline void to_hdf5_inner(hid_t group_id) const override {};

// Accessor methods
const std::shared_ptr<moab::DagMC>& dagmc_ptr() const { return dagmc_ptr_; }
moab::DagMC* dagmc_ptr() const { return dagmc_ptr_.get(); }
int32_t dag_index() const { return dag_index_; }

private:
Expand All @@ -57,6 +59,8 @@ class DAGCell : public Cell {
public:
DAGCell(std::shared_ptr<moab::DagMC> dag_ptr, int32_t dag_idx);

moab::EntityHandle mesh_handle() const;

bool contains(Position r, Direction u, int32_t on_surface) const override;

std::pair<double, int32_t> distance(
Expand All @@ -67,7 +71,7 @@ class DAGCell : public Cell {
void to_hdf5_inner(hid_t group_id) const override;

// Accessor methods
const std::shared_ptr<moab::DagMC>& dagmc_ptr() const { return dagmc_ptr_; }
moab::DagMC* dagmc_ptr() const { return dagmc_ptr_.get(); }
int32_t dag_index() const { return dag_index_; }

private:
Expand Down Expand Up @@ -122,6 +126,16 @@ class DAGUniverse : public Universe {
void legacy_assign_material(
std::string mat_string, std::unique_ptr<DAGCell>& c) const;

//! Return the index into the model cells vector for a given DAGMC volume
//! handle in the universe
//! \param[in] vol MOAB handle to the DAGMC volume set
int32_t cell_index(moab::EntityHandle vol) const;

//! Return the index into the model surfaces vector for a given DAGMC surface
//! handle in the universe
//! \param[in] surf MOAB handle to the DAGMC surface set
int32_t surface_index(moab::EntityHandle surf) const;

//! Generate a string representing the ranges of IDs present in the DAGMC
//! model. Contiguous chunks of IDs are represented as a range (i.e. 1-10). If
//! there is a single ID a chunk, it will be represented as a single number
Expand All @@ -142,6 +156,7 @@ class DAGUniverse : public Universe {
//!< universe in OpenMC's surface vector

// Accessors
moab::DagMC* dagmc_ptr() const { return dagmc_instance_.get(); }
bool has_graveyard() const { return has_graveyard_; }

private:
Expand Down
32 changes: 27 additions & 5 deletions src/dagmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,20 @@ void DAGUniverse::init_geometry()
} // end surface loop
}

int32_t DAGUniverse::cell_index(moab::EntityHandle vol) const
{
// return the index of the volume in the DAGMC instance and then
// adjust by the offset into the model cells for this DAGMC universe
return dagmc_ptr()->index_by_handle(vol) + cell_idx_offset_;
}

int32_t DAGUniverse::surface_index(moab::EntityHandle surf) const
{
// return the index of the surface in the DAGMC instance and then
// adjust by the offset into the model cells for this DAGMC universe
return dagmc_ptr()->index_by_handle(surf) + surf_idx_offset_;
}

std::string DAGUniverse::dagmc_ids_for_dim(int dim) const
{
// generate a vector of ids
Expand Down Expand Up @@ -643,6 +657,11 @@ bool DAGCell::contains(Position r, Direction u, int32_t on_surface) const
return result;
}

moab::EntityHandle DAGCell::mesh_handle() const
{
return dagmc_ptr()->entity_by_index(3, dag_index());
}

void DAGCell::to_hdf5_inner(hid_t group_id) const
{
write_string(group_id, "geom_type", "dagmc", false);
Expand All @@ -668,6 +687,11 @@ DAGSurface::DAGSurface(std::shared_ptr<moab::DagMC> dag_ptr, int32_t dag_idx)
geom_type_ = GeometryType::DAG;
} // empty constructor

moab::EntityHandle DAGSurface::mesh_handle() const
{
return dagmc_ptr()->entity_by_index(2, dag_index());
}

double DAGSurface::evaluate(Position r) const
{
return 0.0;
Expand Down Expand Up @@ -747,18 +771,16 @@ int32_t next_cell(int32_t surf, int32_t curr_cell, int32_t univ)
auto cellp = dynamic_cast<DAGCell*>(model::cells[curr_cell].get());
auto univp = static_cast<DAGUniverse*>(model::universes[univ].get());

moab::EntityHandle surf_handle =
surfp->dagmc_ptr()->entity_by_index(2, surfp->dag_index());
moab::EntityHandle curr_vol =
cellp->dagmc_ptr()->entity_by_index(3, cellp->dag_index());
moab::EntityHandle surf_handle = surfp->mesh_handle();
moab::EntityHandle curr_vol = cellp->mesh_handle();

moab::EntityHandle new_vol;
moab::ErrorCode rval =
cellp->dagmc_ptr()->next_vol(surf_handle, curr_vol, new_vol);
if (rval != moab::MB_SUCCESS)
return -1;

return cellp->dagmc_ptr()->index_by_handle(new_vol) + univp->cell_idx_offset_;
return univp->cell_index(new_vol);
}

} // namespace openmc
Expand Down

0 comments on commit ccb76b3

Please sign in to comment.