Commit e0a54c27 authored by Kiesling, Kalin Rose's avatar Kiesling, Kalin Rose
Browse files

Merge branch 'read_subassembly_output' into 'development'

Pass in output subassembly power/volume data file to PyGriffin

See merge request nstauff/PyGriffin!17
parents 2ad02000 961dba61
Loading
Loading
Loading
Loading
+42 −6
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@ from pathlib import Path
import subprocess
import warnings

import pandas as pd

from . import checkvalue as cv
from .config import PyGriffinConfig

@@ -24,6 +26,11 @@ class PyGriffin:
        Location of Griffin input file
    n_procs : int
        Number of processes in Griffin run
    _keff : float
        Output k-effective from Griffin run
    _subassembly_power_volume : pandas.DataFrame
        Dataframe storing assembly_id, plane_id, power, and volume data
        for each unique (assembly_id, plane_id) combination
    """

    def __init__(self, input, mesh=None, n_procs=1):
@@ -32,6 +39,7 @@ class PyGriffin:
        self.mesh = mesh
        self.n_procs = n_procs
        self._keff = None
        self._subassembly_power_volume = None

    def run(self, input=None,
                  mesh=None,
@@ -194,7 +202,7 @@ class PyGriffin:
            self.run(input=self.mesh, other_args=['--mesh-only', mesh_name])
            return Path(mesh_name).resolve().absolute()

    def postrun(self, griffin_csv_file):
    def postrun(self, griffin_csv_file, griffin_subassembly_output_file):
        """
        Extract Griffin k-effective to output file

@@ -202,36 +210,60 @@ class PyGriffin:
        ----------
        griffin_csv_file : str or pathlib.Path object
            CSV file generated by Griffin which stores eigenvalue information
        griffin_subassembly_output_file : str or pathlib.Path object
            CSV file generated by Griffin which stores subassembly power and volume data

        Returns
        -------
        int
            Errorcode of the Griffin postrun (0 is success,
                                              1 is csv_file not found,
                                              2 is incorrect csv data format
                                              1 is eigenvalue csv_file not found,
                                              2 is incorrect eigenvalue csv data format
                                              3 is eigenvalue not found)
                                              4 is subassembly csv_file not found,
                                              5 is incorrect subassembly csv data format
                                              6 is power/volume data not found)
        """

        if not Path(griffin_csv_file).is_file():
            # CSV file not found
            # Eigenvalue CSV file not found
            return 1
        with open(griffin_csv_file, 'r') as f:
            lines = f.readlines()
        if len(lines) < 3:
            # Insufficient row entries in csv file
            # Insufficient row entries in eigenvalue csv file
            return 2

        keff_field = "eigenvalue"
        header = lines[0].split('\n')[0]
        output_fields = header.split(',')
        if keff_field not in output_fields:
            # Output eigenvalue filed not found in csv file
            # Output eigenvalue field not found in csv file
            return 3
        keff_index = output_fields.index(keff_field)

        result_row = lines[-1].split('\n')[0]
        self.keff = float(result_row.split(',')[keff_index])

        if not Path(griffin_subassembly_output_file).is_file():
            # Subassembly power volume CSV file not found
            return 4

        # Read subassembly CSV file as pandas dataframe
        df = pd.read_csv(griffin_subassembly_output_file, header=0,
                         index_col=False)
        if df.shape[0] < 1:
            # Insufficient row entries in power volume csv file
            return 5

        if df.shape[1] != 4:
            # Incorrect number of output fields in power volume csv file
            return 5
        if 'power' not in df or 'volume' not in df:
            # Output power and volume fields not found in csv file
            return 6

        self._subassembly_power_volume = df
        return 0

    def __call__(self, cwd=None):
@@ -351,3 +383,7 @@ class PyGriffin:
        cv.check_type('Griffin k-effective', keff, Real)
        cv.check_greater_than('Griffin k-effective', keff, 0)
        self._keff = keff

    @property
    def subassembly_power_volume(self):
        return self._subassembly_power_volume
+5 −0
Original line number Diff line number Diff line
Level-0-assembly_id,Level-1-plane_id,not_power,volume
0,0,0,1.0
0,1,0,2.0
1,0,0,1.0
1,1,2.5,2.0
+5 −0
Original line number Diff line number Diff line
Level-0-assembly_id,Level-1-plane_id,power,not_volume
0,0,0,1.0
0,1,0,2.0
1,0,0,1.0
1,1,2.5,2.0
Loading