Code Monkey home page Code Monkey logo

Comments (3)

shimwell avatar shimwell commented on August 15, 2024

ah sorry I misunderstood, the above script gets tags while this one gets material ids https://gist.github.com/pshriwise/ba911ea159d3b6cc0152cd6c4c2f7864

from openmc-dagmc-wrapper.

shimwell avatar shimwell commented on August 15, 2024
from pymoab import core, types


def load_moab_file(filename):
    mb = core.Core()
    mb.load_file(filename)
    return mb


def find_moab_ids_by_type(mb: core.Core(), geom_type: str) -> List[int]:
    """Returns the ids for a given geometry entity type.

    mb: A PyMOAB instance with the file of interest already loaded
    geom_type: The type of geometry entity to provide IDs for. One of ("Group",
        "Volume", "Surface", "Curve", "Vertex")

    Returns: a sorted list of IDs for the geometry type
    """

    _VALID_GEOM_TYPES =  ("Group", "Volume", "Surface", "Curve", "Vertex")

    if geom_type not in _VALID_GEOM_TYPES:
        raise
    # retrieve the category tag on the instance
    try:

        cat_tag = mb.tag_get_handle(types.CATEGORY_TAG_NAME)

    except types.MB_ENTITY_NOT_FOUND:

        raise RuntimeError("The category tag could not be found in the PyMOAB instance."

                           "Please check that the DAGMC file has been loaded.")

    # get the id tag
    gid_tag = mb.tag_get_handle(types.GLOBAL_ID_TAG_NAME)
    print(gid_tag)

    # get the set of entities using the provided category tag name
    # (0 means search on the instance's root set)
    ents = mb.get_entities_by_type_and_tag(0, types.MBENTITYSET, [cat_tag], [geom_type])

    # retrieve the IDs of the entities
    ids = mb.tag_get_data(gid_tag, ents).flatten()

    return sorted(list(ids))

from openmc-dagmc-wrapper.

shimwell avatar shimwell commented on August 15, 2024

required functionality has bee added to dagmc-h5m-file-inspector package

from openmc-dagmc-wrapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.