Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

Simplify create_material #104

Open
RemDelaporteMathurin opened this issue Feb 15, 2022 · 0 comments
Open

Simplify create_material #104

RemDelaporteMathurin opened this issue Feb 15, 2022 · 0 comments

Comments

@RemDelaporteMathurin
Copy link
Member

def create_material(material_tag: str, material_entry):
    if isinstance(material_entry, str):
        openmc_material = nmm.Material.from_library(
            name=material_entry, material_id=None
        ).openmc_material
    elif isinstance(material_entry, openmc.Material):
        # sets the material name in the event that it had not been set
        openmc_material = material_entry
    elif isinstance(material_entry, (nmm.Material)):
        # sets the material tag in the event that it had not been set
        openmc_material = material_entry.openmc_material
    else:
        raise TypeError(
            "materials must be either a str, \
            openmc.Material, nmm.MultiMaterial or nmm.Material object \
            not a ",
            type(material_entry),
            material_entry,
        )
    openmc_material.name = material_tag
    return openmc_material

I find it more intuitive if it's just

def create_material(material_entry):
    if isinstance(material_entry, str):
        openmc_material = nmm.Material.from_library(
            name=material_entry, material_id=None
        ).openmc_material
    elif isinstance(material_entry, openmc.Material):
        # sets the material name in the event that it had not been set
        openmc_material = material_entry
    elif isinstance(material_entry, (nmm.Material)):
        # sets the material tag in the event that it had not been set
        openmc_material = material_entry.openmc_material
    else:
        raise TypeError(
            "materials must be either a str, \
            openmc.Material, nmm.MultiMaterial or nmm.Material object \
            not a ",
            type(material_entry),
            material_entry,
        )
    return openmc_material

and the name of the material is assigned in odw.Materials.set_openmc_materials

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant