ukaea/neutronics_material_maker

Serpent mat card - finer control

CoronelBuendia opened this issue · 2 comments

In BLUEPRINT I need to assign the same material to multiple components, and I have a little input writer which does this automatically. Perhaps I am doing this wrong: I make a new material for each part and I name the material after that part.

So PF1 and PF2 will each have their own material cards with the same material in them. I wanted to do this because:

  • I doubt it will really affect performance
  • Serpent plot colouring
  • In the long run, irradiation history, transmutation, and waste.. but maybe it doesn't work this way.

Anyway, my use case would require something like:

EUROFER = Material('Eurofer')
matcard = EUROFER.serpent_material_card(name, color)

My proposed solution does not work with the @property decorator:

    @staticmethod
    def _colr_kwarg(rgblist):
        if type(rgblist) not in (tuple, list, np.ndarray) or len(rgblist) != 3:
            raise ValueError("3-length RGB color tuple please.")
        return ' '.join([str(i) for i in np.array(rgblist).clip(0, 256)])

    #@property
    def serpent_material_card(self, **kwargs):

        density = self.atom_density_per_barn_per_cm
        if density == None :
            density = -1 * self.density_g_per_cm3
        name = kwargs.get('name', self.description)
        color = ' rgb '+self._colr_kwarg(kwargs.get('color', [0, 128, 128]))
        material_card = 'mat ' + name + ' ' + str(density) + color + '\n'

I'm not sure how you are using the function or how it is being used as a property elsewhere so I don't really want to break it...

The alternative would be something like:

EUROFER = Material('Eurofer')
EUROFER.description = 'blanket'
EUROFER.color = '0 45 234'
mat_card = EUROFER.serpent_material_card()

Where

    @property
    def serpent_material_card(self):
        density = self.atom_density_per_barn_per_cm
        if density == None :
            density = -1 * self.density_g_per_cm3
        if hasattr(self, 'color'):
                color = self.color
        else:
                color = ''
        material_card = 'mat ' + self.description + ' ' + str(density) + color + '\n'

What do you think?

The description part is used by the cell cards as well to link the cells to a material so I might have to make a change there as well

OK I don't know about that..

The only change in behaviour which I know will definitely happen is as follows...

Losing the @property will mean that instead of:

Material.serpent_material_card

You will have to say:

Material.serpent_material_card()

I had to modify the testcase in this way:

    def test_material_serpent_material_card_type(self):
        new_material = nmm.Material('SS-316LN-IG')
        assert type(new_material.serpent_material_card) == str

Becomes

    def test_material_serpent_material_card_type(self):
        new_material = nmm.Material('SS-316LN-IG')
        assert type(new_material.serpent_material_card()) == str