Beispiel #1
0
    def setUp(self):
        self.listener = ConcentrationPrinter()

        folder = os.path.join(os.path.dirname(rmgpy.__file__), 'solver/files/listener/')
        input_file = os.path.join(folder, 'input.py')
        chemkin_file = os.path.join(folder, 'chemkin/chem.inp')
        spc_dict = os.path.join(folder, 'chemkin/species_dictionary.txt')

        self.rmg = load_rmg_py_job(input_file, chemkin_file, spc_dict, generate_images=False, check_duplicates=False)
Beispiel #2
0
    def set_up(self):
        """
        Read in the chemkin file, species dictionary, and RMG input file.
        If the user requested SA, simulate the job with SA and generate the output csv files.
        If SA is not requested, only simulate the job to obtain species profiles.

        Raises:
            FileNotFoundError: If the RMG adapter does not properly read the rmg input file.
            ValueError: If RMG SA is not implemented for the given reactor type.
        """

        # set up directories
        if len(self.observable_list):
            # store SA results in an SA directory
            self.rmg_input_file = self.paths['SA input']
            if not os.path.isdir(self.paths['SA']):
                os.mkdir(self.paths['SA'])
            if not os.path.isdir(self.paths['SA solver']):
                os.mkdir(self.paths['SA solver'])
            if os.path.isfile(self.paths['SA input']):
                os.remove(self.paths['SA input'])
        else:
            # store regular simulation results in solver directory that RMG creates automatically
            self.rmg_input_file = self.paths['RMG input']

        # must copy the input file since load_rmg_py_job creates many directories based on the input file's location
        if not os.path.isfile(self.rmg_input_file):
            shutil.copyfile(src=self.paths['RMG input'],
                            dst=self.rmg_input_file)

        # create rmg object that all methods can access
        self.rmg_model = load_rmg_py_job(
            input_file=self.rmg_input_file,
            chemkin_file=self.paths['chem annotated'],
            species_dict=self.paths['species dict'],
            generate_images=True,
            use_chemkin_names=False,
            check_duplicates=False,
        )
        if self.rmg_model is None:
            raise FileNotFoundError(
                'The RMG adapter did not properly read the rmg input file.')

        # update the rmg object to perform SA if applicable
        if len(self.observable_list):
            self.logger.info(
                'Running a simulation with SA using RMGConstantTP...')
            self.observable_species = [
                species
                for species in self.rmg_model.reaction_model.core.species
                if species.label in self.observable_list
            ]

            for i, reaction_system in enumerate(
                    self.rmg_model.reaction_systems):
                reaction_system.sensitive_species = self.observable_species
                reaction_system.sensitivity_threshold = self.t3['sensitivity'][
                    'SA_threshold']
                if hasattr(reaction_system,
                           'Trange') and reaction_system.Trange is not None:
                    temperature = sum([
                        t.value_si for t in reaction_system.Trange
                    ]) / len(reaction_system.Trange)
                    self.logger.info(
                        f'An average temperature of {temperature} K is taken for the SA'
                        f'for the RMG reactor number {i}')
                else:
                    temperature = reaction_system.T.value_si
                reaction_system.sens_conditions['T'] = temperature
                if isinstance(reaction_system, SimpleReactor):
                    if hasattr(
                            reaction_system,
                            'Prange') and reaction_system.Prange is not None:
                        pressure = sum([
                            p.value_si for p in reaction_system.Prange
                        ]) / len(reaction_system.Prange)
                        self.logger.info(
                            f'An average pressure of {pressure} Pa is taken for the SA'
                            f'for the RMG reactor number {i}')
                    else:
                        pressure = reaction_system.P.value_si
                    reaction_system.sens_conditions['P'] = pressure
                elif isinstance(reaction_system, LiquidReactor):
                    if hasattr(
                            reaction_system,
                            'Vrange') and reaction_system.Vrange is not None:
                        volume = sum([v for v in reaction_system.Vrange
                                      ]) / len(reaction_system.Vrange)
                        self.logger.info(
                            f'An average volume of {volume} m^3 is taken for the SA'
                            f'for the RMG reactor number {i}')
                    else:
                        volume = reaction_system.V
                    reaction_system.sens_conditions['V'] = volume
                else:
                    raise NotImplementedError(
                        f'RMG SA not implemented for Reactor type {type(reaction_system)}.'
                    )
        else:
            self.logger.info('Running a simulation using RMGConstantTP...')