def __init__(self, moFile, pkgName=None):
        super(OMModelWrapper,self).__init__()

        self.moFile = moFile
        self._init_xml = moFile + "_init.xml"
        self._prm_attrib = []
        self._var_attrib = []
        self._wdir = os.getcwd()

        OM_build.build_modelica_model(usr_dir=self._wdir,fname=self.moFile, additionalLibs = pkgName)
        try:
            etree = lmm.get_etree(self._init_xml)
        except:
            sys.exit("FMI xml file incorrect or not exist")

        # Get the simulation settings
        sim_set = etree.find("DefaultExperiment").attrib
        self.add('startTime', Float(float(sim_set['startTime']),
                          iotype ='in',
                          desc   ='startTime',
                          units  ='s'))
        self.add('stopTime', Float(float(sim_set['stopTime']),
                          iotype ='in',
                          desc   ='stopTime',
                          units  ='s'))
        self.add('stepSize', Float(float(sim_set['stepSize']),
                          iotype ='in',
                          desc   ='stepSize',
                          units  ='s'))
        self.add('tolerance', Float(float(sim_set['tolerance']),
                          iotype ='in',
                          desc   ='tolerance'))
        self.add('solver', Str(sim_set['solver'],
                          iotype ='in',
                          desc   ='solver'))
        # Model param inputs
        varElem = etree.find("ModelVariables").getchildren()
        file_name = self.moFile+".mo"
        for var in varElem:
            if (file_name in var.attrib['fileName']) and\
               var.attrib['variability']=="parameter":
                print ' ', var.attrib['name']
                kwargs = {'iotype':'in', 'desc':var.attrib['name']}
                if var.find('Real') is not None:
                    value = float(var.find('Real').attrib['start'])
                    self.add(var.attrib['name'],Float(value,**kwargs))
                elif var.find('Integer') is not None:
                    value = int(var.find('Integer').attrib['start'])
                    self.add(var.attrib['name'],Int(value,**kwargs))
                elif var.find('Boolean') is not None:
                    if var.find('Boolean').attrib['start']=="0.0": value = 0
                    else: value = 1
                    kwargs['desc'] = kwargs['desc']+', boolean'
                    self.add(var.attrib['name'], Int(value,**kwargs))
                self._prm_attrib += [var.attrib['name']]


        # Next, outputs are found. Any variables except "parameters" in the
        # model file becomes output.
        for var in varElem:
            if (file_name in var.attrib['fileName']) and\
               var.attrib['variability'] != "parameter":
                print ' ', var.attrib['name']
                kwargs = {'iotype':'out', 'desc':var.attrib['name']}
                if var.find('Real') is not None:
                    kwargs['dtype'] = np.float
                elif var.find('Integer') is not None:
                    kwargs['dtype'] = np.int
                elif var.find('Boolean') is not None:
                    kwargs['dtype'] = np.bool
                    kwargs['desc'] = kwargs['desc']+', boolean'
                    self.add(var.attrib['name'], Int(value,**kwargs))
                self.add(var.attrib['name'],Array(np.array([]),**kwargs))
                self._var_attrib += [var.attrib['name']]
        self.time = Array(np.array([]),dtype=np.float,iotype='out',desc='time',units='s')
        self._var_attrib += ['time']
Example #2
0
    def __init__(self, fully_qualified_class_name, addl_pkg_abs_path=None):
        super(OMModelWrapper, self).__init__()

        self.class_name = fully_qualified_class_name.split('.')[-1]
        self._prm_attrib = []
        self._var_attrib = []
        self._wdir = os.getcwd()

        OM_build.build_modelica_model(
            usr_dir=self._wdir,
            fully_qualified_class_name=fully_qualified_class_name,
            additional_libs=addl_pkg_abs_path)
        self._init_xml = self.class_name + "_init.xml"
        try:
            etree = lmm.get_etree(self._init_xml)
        except:
            sys.exit("FMI xml file incorrect or not exist")

        # Get the simulation settings
        sim_set = etree.find("DefaultExperiment").attrib
        for param_name in [
                'startTime', 'stopTime', 'stepSize', 'tolerance', 'solver'
        ]:
            print(param_name, sim_set[param_name])
            self.add_param(param_name, val=sim_set[param_name])

        # Model param inputs
        model_variables = etree.find("ModelVariables").getchildren()
        file_name = self.class_name + ".mo"
        for var in model_variables:
            if (file_name in var.attrib['fileName']
                ) and var.attrib['variability'] == "parameter":
                name = var.attrib['name']
                print ' ', name
                if var.find('Real') is not None:
                    value = float(var.find('Real').attrib['start'])
                    self.add_param(name, val=value)
                elif var.find('Integer') is not None:
                    value = int(var.find('Integer').attrib['start'])
                    self.add_param(name, val=value)
                elif var.find('Boolean') is not None:
                    if var.find('Boolean').attrib['start'] == "0.0":
                        value = 0
                    else:
                        value = 1
                    self.add_param(name, val=value)
                self._prm_attrib += [name]

        # Next, outputs are found. Any variables except "parameters" in the
        # model file becomes output.
        for var in model_variables:
            if (file_name in var.attrib['fileName']
                ) and var.attrib['variability'] != "parameter":
                name = var.attrib['name']
                print ' ', name

                val = None
                if var.find('Real') is not None:
                    val = 0.0
                elif var.find('Integer') is not None:
                    val = 0
                elif var.find('Boolean') is not None:
                    val = 0

                try:
                    self.add_output(name, val=val, pass_by_obj=True)
                    self._var_attrib += [name]
                except:
                    pass

        self.add_output('time', val=0.0, pass_by_obj=True)
        self._var_attrib += ['time']
Example #3
0
    def __init__(self, fully_qualified_class_name, addl_pkg_abs_path=None):
        super(OMModelWrapper, self).__init__()

        self.class_name = fully_qualified_class_name.split('.')[-1]
        self._prm_attrib = []
        self._var_attrib = []
        self._wdir = os.getcwd()

        OM_build.build_modelica_model(usr_dir=self._wdir, fully_qualified_class_name=fully_qualified_class_name, additional_libs=addl_pkg_abs_path)
        self._init_xml = self.class_name + "_init.xml"
        try:
            etree = lmm.get_etree(self._init_xml)
        except:
            sys.exit("FMI xml file incorrect or not exist")

        # Get the simulation settings
        sim_set = etree.find("DefaultExperiment").attrib
        for param_name in ['startTime', 'stopTime', 'stepSize', 'tolerance', 'solver']:
            print (param_name, sim_set[param_name])
            self.add_param(param_name, val=sim_set[param_name])

        # Model param inputs
        model_variables = etree.find("ModelVariables").getchildren()
        file_name = self.class_name + ".mo"
        for var in model_variables:
            if (file_name in var.attrib['fileName']) and var.attrib['variability'] == "parameter":
                name = var.attrib['name']
                print ' ', name
                if var.find('Real') is not None:
                    value = float(var.find('Real').attrib['start'])
                    self.add_param(name, val=value)
                elif var.find('Integer') is not None:
                    value = int(var.find('Integer').attrib['start'])
                    self.add_param(name, val=value)
                elif var.find('Boolean') is not None:
                    if var.find('Boolean').attrib['start'] == "0.0":
                        value = 0
                    else:
                        value = 1
                    self.add_param(name, val=value)
                self._prm_attrib += [name]

        # Next, outputs are found. Any variables except "parameters" in the
        # model file becomes output.
        for var in model_variables:
            if (file_name in var.attrib['fileName']) and var.attrib['variability'] != "parameter":
                name = var.attrib['name']
                print ' ', name

                val = None
                if var.find('Real') is not None:
                    val = 0.0
                elif var.find('Integer') is not None:
                    val = 0
                elif var.find('Boolean') is not None:
                    val = 0

                try:
                    self.add_output(name, val=val, pass_by_obj=True)
                    self._var_attrib += [name]
                except:
                    pass

        self.add_output('time', val=0.0, pass_by_obj=True)
        self._var_attrib += ['time']
Example #4
0
    def __init__(self, moFile, pkgName=None):
        super(OMModelWrapper, self).__init__()

        self.moFile = moFile
        self._init_xml = moFile + "_init.xml"
        self._prm_attrib = []
        self._var_attrib = []
        self._wdir = os.getcwd()

        OM_build.build_modelica_model(usr_dir=self._wdir,
                                      fname=self.moFile,
                                      additionalLibs=pkgName)
        try:
            etree = lmm.get_etree(self._init_xml)
        except:
            sys.exit("FMI xml file incorrect or not exist")

        # Get the simulation settings
        sim_set = etree.find("DefaultExperiment").attrib
        self.add(
            'startTime',
            Float(float(sim_set['startTime']),
                  iotype='in',
                  desc='startTime',
                  units='s'))
        self.add(
            'stopTime',
            Float(float(sim_set['stopTime']),
                  iotype='in',
                  desc='stopTime',
                  units='s'))
        self.add(
            'stepSize',
            Float(float(sim_set['stepSize']),
                  iotype='in',
                  desc='stepSize',
                  units='s'))
        self.add(
            'tolerance',
            Float(float(sim_set['tolerance']), iotype='in', desc='tolerance'))
        self.add('solver', Str(sim_set['solver'], iotype='in', desc='solver'))
        # Model param inputs
        varElem = etree.find("ModelVariables").getchildren()
        file_name = self.moFile + ".mo"
        for var in varElem:
            if (file_name in var.attrib['fileName']) and\
               var.attrib['variability']=="parameter":
                print ' ', var.attrib['name']
                kwargs = {'iotype': 'in', 'desc': var.attrib['name']}
                if var.find('Real') is not None:
                    value = float(var.find('Real').attrib['start'])
                    self.add(var.attrib['name'], Float(value, **kwargs))
                elif var.find('Integer') is not None:
                    value = int(var.find('Integer').attrib['start'])
                    self.add(var.attrib['name'], Int(value, **kwargs))
                elif var.find('Boolean') is not None:
                    if var.find('Boolean').attrib['start'] == "0.0": value = 0
                    else: value = 1
                    kwargs['desc'] = kwargs['desc'] + ', boolean'
                    self.add(var.attrib['name'], Int(value, **kwargs))
                self._prm_attrib += [var.attrib['name']]

        # Next, outputs are found. Any variables except "parameters" in the
        # model file becomes output.
        for var in varElem:
            if (file_name in var.attrib['fileName']) and\
               var.attrib['variability'] != "parameter":
                print ' ', var.attrib['name']
                kwargs = {'iotype': 'out', 'desc': var.attrib['name']}
                if var.find('Real') is not None:
                    kwargs['dtype'] = np.float
                elif var.find('Integer') is not None:
                    kwargs['dtype'] = np.int
                elif var.find('Boolean') is not None:
                    kwargs['dtype'] = np.bool
                    kwargs['desc'] = kwargs['desc'] + ', boolean'
                    self.add(var.attrib['name'], Int(value, **kwargs))
                self.add(var.attrib['name'], Array(np.array([]), **kwargs))
                self._var_attrib += [var.attrib['name']]
        self.time = Array(np.array([]),
                          dtype=np.float,
                          iotype='out',
                          desc='time',
                          units='s')
        self._var_attrib += ['time']