def test_carbon_black_stochastoc(carbon_black_cuds: Cuds, flask_client,
                                 mocker) -> None:
    wrapper = _case_runner(case_cuds=carbon_black_cuds,
                           engine=CarbonBlackEngine(),
                           model_flag=KineticsSession.CB_STOCHASIC,
                           client=flask_client,
                           mocker=mocker)

    # Find all the output CUDS
    part_num_dens = cuds_search.find_cuds_objects_by_oclass(
        oclass=CMCL.PARTICLE_NUMBER_DENSITIES, root=wrapper, rel=None)
    part_num_size_classes = cuds_search.find_cuds_objects_by_oclass(
        oclass=CMCL.PARTICLE_SIZE_CLASSES, root=wrapper, rel=None)
    prim_num_dens = cuds_search.find_cuds_objects_by_oclass(
        oclass=CMCL.PRIMARY_PARTICLE_NUMBER_DENSITIES, root=wrapper, rel=None)
    prim_num_size_classes = cuds_search.find_cuds_objects_by_oclass(
        oclass=CMCL.PRIMARY_PARTICLE_SIZE_CLASSES, root=wrapper, rel=None)
    part_fract_dim = cuds_search.find_cuds_objects_by_oclass(
        oclass=CMCL.PARTICLE_MEAN_FRACTAL_DIMENSION, root=wrapper, rel=None)
    # check all the output CUDS
    assert len(part_num_dens) == 1
    assert part_num_dens[0].value_string != ""

    assert len(part_num_size_classes) == 1
    assert part_num_size_classes[0].value_string != ""

    assert len(prim_num_dens) == 1
    assert prim_num_dens[0].value_string != ""

    assert len(prim_num_size_classes) == 1
    assert prim_num_size_classes[0].value_string != ""

    assert len(part_fract_dim) == 1
    assert part_fract_dim[0].value != 0.0
def test_carbon_black_momic(carbon_black_cuds: Cuds, flask_client,
                            mocker) -> None:
    wrapper = _case_runner(case_cuds=carbon_black_cuds,
                           engine=CarbonBlackEngine(),
                           model_flag=KineticsSession.CB_MOMIC,
                           client=flask_client,
                           mocker=mocker)

    # Find all the output CUDS
    mean_part_size = cuds_search.find_cuds_objects_by_oclass(
        oclass=CMCL.MEAN_PARTICLE_SIZE, root=wrapper, rel=None)
    part_num_dens = cuds_search.find_cuds_objects_by_oclass(
        oclass=CMCL.PARTICLE_NUMBER_DENSITY, root=wrapper, rel=None)
    part_vol_frac = cuds_search.find_cuds_objects_by_oclass(
        oclass=CMCL.PARTICLE_VOLUME_FRACTION, root=wrapper, rel=None)

    # check all the output CUDS
    assert len(mean_part_size) == 1
    assert mean_part_size[0].value != 0.0

    assert len(part_num_dens) == 1
    assert part_num_dens[0].value != 0.0

    assert len(part_vol_frac) == 1
    assert part_vol_frac[0].value != 0.0
Example #3
0
    def determineTemplate(self, root_cuds_object, modelFlag) -> str:
        """Determines which simulation template to use based on the input
        CUDS data.

        Arguments:
            root_cuds_object -- Root CUDS object representing input data
            modelFlag -- Integer for model (see KineticsSession for values)

        Returns:
            Appropriate simulation template name
        """

        # Find the EAT Process object
        eat_process = search.find_cuds_objects_by_oclass(CMCL.EAT_PROCESS,
                                                         root_cuds_object,
                                                         rel=CMCL.HAS_PART)[0]

        if modelFlag == KineticsSession.EAT_GPF:
            # GPF
            simulation_template = agent_cases.EAT_GPF

            # Find GPF object
            gpf = search.find_cuds_objects_by_oclass(
                CMCL.GPF, eat_process, rel=CMCL.HAS_PROPER_PARTICIPANT)[0]

            # Add outputs
            gpf.add(CMCL.PM_FILTRATION_EFFICIENCY(value=0.0, unit="-"),
                    CMCL.PN_FILTRATION_EFFICIENCY(value=0., unit="-"),
                    rel=CMCL.HAS_QUANTITATIVE_PROPERTY)

        elif modelFlag == KineticsSession.EAT_TWC:
            # TWC
            simulation_template = agent_cases.EAT_TWC

            # Find TWC object
            twc = search.find_cuds_objects_by_oclass(
                CMCL.TWC, eat_process, rel=CMCL.HAS_PROPER_PARTICIPANT)[0]

            # Add outputs
            twc.add(CMCL.NOX_CAPTURE_EFFICIENCY(value=0.0, unit="-"),
                    CMCL.CO_CAPTURE_EFFICIENCY(value=0.0, unit="-"),
                    CMCL.CXHY_CAPTURE_EFFICIENCY(value=0.0, unit="-"),
                    rel=CMCL.HAS_QUANTITATIVE_PROPERTY)

        else:
            return "ERROR"

        print("Detected simulation template as %s" %
              (simulation_template.template))
        return simulation_template
Example #4
0
    def registerOutput(root_cuds_object, json_out_list, json_inp_dict, outSemSynMap, synEntityToCUDSmap):
        """Registers the passed quantity as an output within the input list.

        Arguments:
            root_cuds_object    -- Root of CUDS object representing inputs
            json_out_list       -- JSON list that would store a given output
            json_inp_dict       -- JSON inputs dictionary - used for special transformations
            outSemSynMap        -- object providing semantic-syntactic mapping for a given output
            synEntityToCUDSmap  -- Dictionary which stores a mapping between syntacitc (key) output
                                   representation that engine understands and the concrete CUDS
                                   instance that the it is associated with
        """

        # Use the oclass name/type associated with a given input from inp_dict_loc dictionary to find the concrete cuds instance
        # that represents this input
        outputCUDS = search.find_cuds_objects_by_oclass(outSemSynMap.semEntity, root_cuds_object, rel=None)
        if not outputCUDS:
            return

        outputCUDS = outputCUDS[0]
        # Get syntactic output keys
        synValueEntities = outSemSynMap.synValueEntity

        # Register the outputs
        json_out_list.extend(synValueEntities)

        # Update synEntityToCUDSmap
        CUDSAdaptor.updateOutputsCudsMap(outputCUDS, outSemSynMap, json_inp_dict, synEntityToCUDSmap)
Example #5
0
    def _create_input(self, sims, **kwargs):
        with open(self._file_path_root + self._session._input_file, "w+") as f:
            for s in sims:
                total_energy = simple_search.find_cuds_objects_by_oclass(
                    oclass=QE.TotalEnergy, root=s, rel=QE.HAS_PART)[0].value
                volume = simple_search.find_cuds_objects_by_oclass(
                    oclass=QE.Volume, root=s, rel=QE.HAS_PART)[0].value
                f.write(f"{volume} {total_energy}\n")
        self.params = {
            "Lattice parameter": "au",
            "type": "noncubic",
            "equation of state": self._session._calculation_type,
            "Input": self._file_path_root + self._session._input_file,
            "Output": self._file_path_root + self._session._output_file,
        }

        super()._modify_input(sim, **kwargs)
def test_eat_gpf(eat_gpf_cuds: Cuds, flask_client, mocker) -> None:
    wrapper = _case_runner(case_cuds=eat_gpf_cuds,
                           engine=EATEngine(),
                           model_flag=KineticsSession.EAT_GPF,
                           client=flask_client,
                           mocker=mocker)

    # Find all the output CUDS
    pm_eff = cuds_search.find_cuds_objects_by_oclass(
        oclass=CMCL.PM_FILTRATION_EFFICIENCY, root=wrapper, rel=None)
    pn_eff = cuds_search.find_cuds_objects_by_oclass(
        oclass=CMCL.PN_FILTRATION_EFFICIENCY, root=wrapper, rel=None)

    # check all the output CUDS
    assert len(pm_eff) == 1
    assert pm_eff[0].value != 0.0

    assert len(pn_eff) == 1
    assert pn_eff[0].value != 0.0
Example #7
0
 def test_find_cuds_objects_by_oclass(self):
     """Test find by cuba key."""
     c, p1, p2, p3, n1, n2, s1 = get_test_city()
     self.assertEqual(
         find_cuds_objects_by_oclass(city.City, c, cuba.activeRelationship),
         [c],
     )
     found = find_cuds_objects_by_oclass(city.Citizen, c,
                                         cuba.activeRelationship)
     self.assertEqual(len(found), 3)
     self.assertEqual(set(found), {p1, p2, p3})
     found = find_cuds_objects_by_oclass(city.Neighborhood, c,
                                         cuba.activeRelationship)
     self.assertEqual(set(found), {n1, n2})
     self.assertEqual(len(found), 2)
     self.assertEqual(
         find_cuds_objects_by_oclass(city.Street, c,
                                     cuba.activeRelationship),
         [s1],
     )
     found = find_cuds_objects_by_oclass(cuba.Entity, c, cuba.relationship)
     self.assertEqual(set(found), {c, p1, p2, p3, n1, n2, s1})
Example #8
0
    def registerInput(root_cuds_object, json_inp_dict, inpSemSynMap):
        """Registers the passed quantity as an input within the input JSON dict.

        Arguments:
            root_cuds_object    -- Root of CUDS object representing inputs
            json_inp_dict       -- JSON dictionary that would store a given input syntactic representation
            inpSemSynMap        -- object providing semantic-syntactic mapping for a given input
        """

        # Use the semEntity type associated with a given input from inpSemSynMap object to find the concrete cuds instance
        # that represents this input
        if inpSemSynMap.transFunc is not None:
            inputValue, inputUnit = CUDSAdaptor.getTransformedInput(root_cuds_object, inpSemSynMap, json_inp_dict)
        else:
            inputCUDS = search.find_cuds_objects_by_oclass(inpSemSynMap.semEntity, root_cuds_object, rel=None)
            if not inputCUDS:
                return

            inputCUDS = inputCUDS[0]

            # Store input cuds value and unit. the engine only accepts the string values, hence the conversion
            inputUnit = inputCUDS.unit

            # NOTE in order to support two possible values in ontological entities (float and string) there
            # are two "VALUE" cuds entities introduced: "VALUE" and "VALUE_STRING". These are further attached
            # to appropriate cuds entities as attribtues. In order to check if a given cuds has either former
            # or latter attribtue all its attributes names are put into a list below and are inspected.
            # NOTE this code will likely change in the future once a proper vector datatype support is added
            # to the simphony core
            inputCUDSattributeNames = [str(attr_name).lower() for attr_name in inputCUDS.get_attributes().keys()]
            if any('value_string' in attr_name for attr_name in inputCUDSattributeNames):
                # this cuds value is stored via "value_string" attribute
                inputValue = str(inputCUDS.value_string)
            else:
                inputValue = str(inputCUDS.value)

        # Not a valid input parameter, do not register
        if (inputValue == None) or (type(inputValue) is list and len(inputValue) == 0):
            return
        if inputValue == "":
            return

        # Register the input
        # Get the syntactic description of this input value and unit keys that the engine will understand
        inputSynValueKey = inpSemSynMap.synValueEntity
        inputSynUnitKey = inpSemSynMap.synUnitEntity

        json_inp_dict[inputSynValueKey] = inputValue
        # update the unit key only once
        if inputSynUnitKey is not None and inputSynUnitKey not in json_inp_dict:
            json_inp_dict[inputSynUnitKey] = inputUnit
def test_eat_twc(eat_twc_cuds: Cuds, flask_client, mocker) -> None:
    wrapper = _case_runner(case_cuds=eat_twc_cuds,
                           engine=EATEngine(),
                           model_flag=KineticsSession.EAT_TWC,
                           client=flask_client,
                           mocker=mocker)

    # Find all the output CUDS
    nox_capt_eff = cuds_search.find_cuds_objects_by_oclass(
        oclass=CMCL.NOX_CAPTURE_EFFICIENCY, root=wrapper, rel=None)
    co_capt_eff = cuds_search.find_cuds_objects_by_oclass(
        oclass=CMCL.CO_CAPTURE_EFFICIENCY, root=wrapper, rel=None)
    cxhy_capt_eff = cuds_search.find_cuds_objects_by_oclass(
        oclass=CMCL.CXHY_CAPTURE_EFFICIENCY, root=wrapper, rel=None)

    # check all the output CUDS
    assert len(nox_capt_eff) == 1
    assert nox_capt_eff[0].value != 0.0

    assert len(co_capt_eff) == 1
    assert co_capt_eff[0].value != 0.0

    assert len(cxhy_capt_eff) == 1
    assert cxhy_capt_eff[0].value != 0.0
Example #10
0
    def getTransformedInput(root_cuds_object, inpSemSynMap, json_inp_dict):
        """Transforms the value of a given input by
           applying the transform function associated wits this input
           in the inp_dict_loc dictionary.

        Arguments:
            root_cuds_object    -- Root of CUDS object representing inputs
            inpSemSynMap        -- object providing semantic-syntactic mapping for a given input
            json_inp_dict       -- JSON dictionary that would store a given input

        Returns:
            transf_value    -- value after the transform operation
            transf_unit     -- unit after the transform operation
        """

        # get the transform function handle
        transf_func = inpSemSynMap.transFunc

        # assess all oclasses and their corresponding cuds instances needed
        # for the transformation

        transf_args_values = []
        for semEntity in inpSemSynMap.semEntity:
            inputCuds = search.find_cuds_objects_by_oclass(semEntity, root_cuds_object, rel=None)
            if not inputCuds:
                return

            inputCuds = inputCuds[0]

            # lookup the function arguments values and create the arguments array to be passed
            # to the function
            inputCUDSattributeNames = [str(attr_name).lower() for attr_name in inputCuds.get_attributes().keys()]
            if any('value_string' in attr_name for attr_name in inputCUDSattributeNames):
                # this cuds value is stored via "value_string" attribute
                transf_args_values.append(inputCuds.value_string)
            else:
                transf_args_values.append(inputCuds.value)

        # if defined, add extra arguments coming from transform function dependency on input values
        if inpSemSynMap.transFuncInpDep is not None:
            for inputDependencyKey in inpSemSynMap.transFuncInpDep:
                transf_args_values.append(json_inp_dict[inputDependencyKey])

        # call the transform function
        transf_value, transf_unit = transf_func(*transf_args_values)
        return transf_value, transf_unit
    def determineTemplate(self, root_cuds_object, modelFlag) -> str:
        """Determines which simulation template to use based on the input
        CUDS data.

        Arguments:
            root_cuds_object -- Root CUDS object representing input data
            modelFlag -- Integer for model (see KineticsSession for values)

        Returns:
            Appropriate simulation template name
        """

        # Find the CB Synthesis object
        cb_synthesis = search.find_cuds_objects_by_oclass(
            CMCL.CB_SYNTHESIS_PROCESS, root_cuds_object, rel=CMCL.HAS_PART)[0]

        # Find the CB Powder object
        cb_powder = search.find_cuds_objects_by_oclass(
            CMCL.CARBON_BLACK_POWDER,
            cb_synthesis,
            rel=CMCL.HAS_PROPER_PARTICIPANT)[0]

        if modelFlag == KineticsSession.CB_STOCHASIC:
            # Stochastic
            simulation_template = agent_cases.STOCH

            # Initialise the relevant outputs
            particle_psd = CMCL.PARTICLE_SIZE_DISTRIBUTION()
            particle_psd.add(CMCL.PARTICLE_NUMBER_DENSITIES(value_string="",
                                                            unit=""),
                             CMCL.PARTICLE_SIZE_CLASSES(value_string="",
                                                        unit=""),
                             rel=CMCL.HAS_QUANTITATIVE_PROPERTY)

            primary_psd = CMCL.PRIMARY_PARTICLE_SIZE_DISTRIBUTION()
            primary_psd.add(CMCL.PRIMARY_PARTICLE_NUMBER_DENSITIES(
                value_string="", unit=""),
                            CMCL.PRIMARY_PARTICLE_SIZE_CLASSES(value_string="",
                                                               unit=""),
                            rel=CMCL.HAS_QUANTITATIVE_PROPERTY)

            # Add the outputs
            cb_powder.add(CMCL.PARTICLE_MEAN_FRACTAL_DIMENSION(value=0.0,
                                                               unit=""),
                          particle_psd,
                          primary_psd,
                          rel=CMCL.HAS_QUANTITATIVE_PROPERTY)

        elif modelFlag == KineticsSession.CB_MOMIC:
            # MoMIC
            simulation_template = agent_cases.MOMIC

            # Add new outputs
            cb_powder.add(CMCL.MEAN_PARTICLE_SIZE(value=0.0, unit=""),
                          CMCL.PARTICLE_NUMBER_DENSITY(value=0.0, unit=""),
                          CMCL.PARTICLE_VOLUME_FRACTION(value=0.0, unit=""),
                          rel=CMCL.HAS_QUANTITATIVE_PROPERTY)

        else:
            return "ERROR"

        print("Detected simulation template as %s" %
              (simulation_template.template))
        return simulation_template
Example #12
0
 def findo(oclass, depth):
     return simple_search.find_cuds_objects_by_oclass(oclass=oclass,
                                                      root=sim,
                                                      rel=QE.HAS_PART)
Example #13
0
 def _get_count(oclass):
     count = 0
     for i in simple_search.find_cuds_objects_by_oclass(
             oclass=oclass, root=sim, rel=QE.HAS_PART):
         count += 1
     return count