def _Test():

    # Import dymola package
    from dymola.dymola_interface import DymolaInterface
    from dymola.dymola_exception import DymolaException

    dymola = None

    #dymola.dymola_interface.DymolaInterface(dymolapath="", port=-1, showwindow=True, debug=False, allowremote=False, nolibraryscripts=False)

    try:
        dymola = DymolaInterface(showwindow=True)
        dymola.simulateModel(
            "Modelica.Mechanics.Rotational.Examples.CoupledClutches")
        print("Simulate")

    except DymolaException as ex:
        print("Error")
Example #2
0
            'delta' : ['gENROU.delta', 'gENSAL.delta', 'gENCLS.delta', 'gENROE.delta', 'gENSAE.delta', 'cSVGN1.delta'],
           'pelec' : ['gENROU.PELEC', 'gENSAL.PELEC', 'gENCLS.PELEC', 'gENROE.PELEC', 'gENSAE.PELEC', 'cSVGN1.PELEC'],
           'speed' : ['gENROU.SPEED', 'gENSAL.SPEED', 'gENCLS.SPEED', 'gENROE.SPEED', 'gENSAE.SPEED', 'cSVGN1.SPEED']}


# In[5]:


#For loop that will iterate between machines, simulate, and create the .csv file
for machineNumber, machineName in enumerate(machines['names']):
    try:
        print(f"{machineName} Simulation Start...")
        dymola.cd("/home/manuelnvro/dev/Gitted/PythonTesting/WorkingDir/Dymola/Machines/" + machineName)
        resultPath = f"/home/manuelnvro/dev/Gitted/PythonTesting/WorkingDir/Dymola/Machines/{machineName}/" + machineName
        result = dymola.simulateModel(machines['path'][machineNumber], 
                                stopTime=10.0,
                                numberOfIntervals = 5000,
                                resultFile = resultPath)
        if not result:
            print("Simulation failed or model was not found. Below is the translation log:\n")
            log = dymola.getLastErrorLog()
            print(log)
        else:
            print(f"{machineName} Simulation OK...")
            print(".csv Writing Start...")
            #Selecting Result File
            sim = SimRes(f"/home/manuelnvro/dev/Gitted/PythonTesting/WorkingDir/Dymola/Machines/{machineName}/{machineName}.mat")
            #Selecting Variables
            variables = ['Time', machines['delta'][machineNumber], machines['pelec'][machineNumber], machines['speed'][machineNumber], 'GEN1.V', 'LOAD.V', 'GEN2.V', 'FAULT.V' ]
            df_variables = pd.DataFrame([], columns = variables)
            for var in variables:
                df_variables.drop(var, axis = 1, inplace = True)
Example #3
0
def dymola_simulation(model_info, path_dymola, solver, printInfo=True):
    '''
    
    '''
    # Retrieving model information
    root_path = model_info['root_path']
    library_path = model_info['library_path']
    model_path = model_info['model_path']
    model_name = model_info['model_name']
    output_path = model_info['output_path']

    dymola = None

    try:
        if printInfo:
            print("Creating and starting Dymola instance")

        # Creating dymola instance
        dymola = DymolaInterface(dymolapath=path_dymola)

        if printInfo:
            print(f"Using Dymola port:" + str(dymola._portnumber))
            print(f"Changing working directory to: {output_path}")

        try:
            if not os.path.exists(output_path):
                os.makedirs(output_path)
                print("Working directory created")
        except OSError as ex:
            print("1: Failed to create folder for working directory")

        # CHANGING THE PATH TO OPENING THE LIBRARY AND THE MODEL
        result = dymola.cd(root_path)
        if not result:
            print("1: Failed to change working directory")

        # Opening OpenIPSL library
        dymola.openModel(library_path)
        if result and printInfo:
            print("Library opened")

        # Opening model
        dymola.openModel(model_path)
        if result and printInfo:
            print("Model opened")

        # CHANGING THE PATH FOR THE WORKING DIRECTORY
        # Note that the model is already opened
        result = dymola.cd(output_path)
        if not result:
            print("1: Failed to change working directory")

        # Simulating the model
        if solver == 'dassl':
            dymola.Execute("Advanced.Define.DAEsolver = true")
            print("DAE setting changed for dassl")

        if solver in ["Rkfix2", "Rkfix4", "Euler"]:
            print("Running simulation...")
            result = dymola.simulateModel(model_name,
                                          method=solver,
                                          stopTime=120,
                                          numberOfIntervals=240000,
                                          tolerance=1e-06,
                                          resultFile=model_name +
                                          "_{}".format(solver))
        else:
            # Settings for dassl
            print("Running simulation...")
            result = dymola.simulateModel(model_name,
                                          method=solver,
                                          stopTime=120,
                                          numberOfIntervals=5000,
                                          tolerance=1e-06,
                                          resultFile=model_name +
                                          "_{}".format(solver))

        if not result:
            print("Simulation failed. Below is the error log:")
            log = dymola.getLastErrorLog()
            print(log)
        else:
            print("Simulation OK")
            # Close Dymola
            dymola.close()

    except DymolaException as ex:
        if printInfo:
            print(("Error: " + str(ex)))
        else:
            pass
    finally:
        if dymola is not None:
            dymola.close()
            dymola = None
Example #4
0
import platform

from dymola.dymola_interface import DymolaInterface
from dymola.dymola_exception import DymolaException

osString = platform.system()
isWindows = osString.startswith("Win")

dymola = None
try:
    # Instantiate the Dymola interface and start Dymola
    dymola = DymolaInterface()

    # Call a function in Dymola and check its return value
    result = dymola.simulateModel("Modelica.Mechanics.Rotational.Examples.CoupledClutches")
    if not result:
        print("Simulation failed. Below is the translation log.")
        log = dymola.getLastErrorLog()
        print(log)
        exit(1)

    dymola.plot(["J1.w", "J2.w", "J3.w", "J4.w"])
    if (isWindows):
        plotPath = "C:/temp/plot.png"
    else:
        plotPath = "/tmp/plot.png";
    dymola.ExportPlotAsImage(plotPath)
    print("OK")
except DymolaException as ex:
    print(("Error: " + str(ex)))
finally:
Example #5
0
)
for tgovernorNumber, tgovernorName in enumerate(tgovernors['names']):
    os.makedirs(f'{tgovernorName}')

# In[5]:

#For loop that will iterate between turbine governors, simulate, and create the .csv fileurb
for tgovernorNumber, tgovernorName in enumerate(tgovernors['names']):
    try:
        print(f"{tgovernorName} Simulation Start...")
        dymola.cd(
            "/home/manuelnvro/dev/Gitted/PythonTesting/WorkingDir/Dymola/TurbineGovernors/"
            + tgovernorName)
        resultPath = f"/home/manuelnvro/dev/Gitted/PythonTesting/WorkingDir/Dymola/TurbineGovernors/{tgovernorName}/" + tgovernorName
        result = dymola.simulateModel(tgovernors['path'][tgovernorNumber],
                                      stopTime=10.0,
                                      numberOfIntervals=5000,
                                      resultFile=resultPath)
        if not result:
            print(
                "Simulation failed or model was not found. Below is the translation log:\n"
            )
            log = dymola.getLastErrorLog()
            print(log)
            try:
                os.chdir(
                    f"/home/manuelnvro/dev/Gitted/PythonTesting/WorkingDir/Dymola/TurbineGovernors/{tgovernorName}/"
                )
                os.remove("dsin.txt")
            except:
                pass
        else:
Example #6
0
    f"/home/manuelnvro/dev/Gitted/PythonTesting/WorkingDir/Dymola/Exciters/")
for exciterNumber, exciterName in enumerate(exciters['names']):
    os.makedirs(f'{exciterName}')

# In[5]:

#For loop that will iterate between exciters, simulate, and create the .csv file
for exciterNumber, exciterName in enumerate(exciters['names']):
    try:
        print(f"{exciterName} Simulation Start...")
        dymola.cd(
            "/home/manuelnvro/dev/Gitted/PythonTesting/WorkingDir/Dymola/Exciters/"
            + exciterName)
        resultPath = f"/home/manuelnvro/dev/Gitted/PythonTesting/WorkingDir/Dymola/Exciters/{exciterName}/" + exciterName
        result = dymola.simulateModel(exciters['path'][exciterNumber],
                                      stopTime=10.0,
                                      numberOfIntervals=5000,
                                      resultFile=resultPath)
        if not result:
            print(
                "Simulation failed or model was not found. Below is the translation log:\n"
            )
            log = dymola.getLastErrorLog()
            print(log)
            try:
                os.chdir(
                    f"/home/manuelnvro/dev/Gitted/PythonTesting/WorkingDir/Dymola/Exciters/{exciterName}/"
                )
                os.remove("dsin.txt")
            except:
                pass
        else:
Example #7
0
for machineNumber, machineName in enumerate(machines['names']):
    os.makedirs(f'{machineName}')

# In[28]:

#For loop that will iterate between machines, simulate, and create the .csv file
for machineNumber, machineName in enumerate(machines['names']):
    try:
        print(f"Fault {machineName} Simulation Start...")
        dymola.cd("" + FMachinesWorkingDir + machineName)
        resultPath = "/" + FMachinesWorkingDir + f"{machineName}/" + machineName
        #Changing the solver if it is CSVGN1
        if machineName == 'CSVGN1':
            result = dymola.simulateModel(machines['path'][machineNumber],
                                          stopTime=10.0,
                                          method="dassl",
                                          tolerance=1e-4,
                                          numberOfIntervals=500,
                                          resultFile=resultPath)
        else:
            result = dymola.simulateModel(machines['path'][machineNumber],
                                          stopTime=10.0,
                                          method="Rkfix2",
                                          tolerance=1e-06,
                                          numberOfIntervals=5000,
                                          resultFile=resultPath)
        if not result:
            print(
                "Simulation failed or model was not found. Below is the translation log:\n"
            )
            log = dymola.getLastErrorLog()
            print(log)
Example #8
0
dymola = DymolaInterface("/opt/dymola-2020-x86_64/bin64/dymola.sh")
#Setting OpenIPSL library
dymola.openModel(
    "/home/manuelnvro/dev/Gitted/PythonTesting/OpenIPSL-master/OpenIPSL/package.mo"
)
print("Dymola Simulation Start...")

# In[5]:

try:
    #Set WorkingDir
    dymola.cd("/home/manuelnvro/dev/Gitted/PythonTesting/WorkingDir/Dymola")
    resultPath = "/home/manuelnvro/dev/Gitted/PythonTesting/WorkingDir/Dymola/EXAC1"
    #Dymola Simulation
    result = dymola.simulateModel("OpenIPSL.Examples.Controls.PSSE.ES.EXAC1",
                                  numberOfIntervals=5000,
                                  resultFile=resultPath)
    if not result:
        print("Simulation failed. Below is the translation log.")
        log = dymola.getLastErrorLog()
        print(log)
        exit(1)
    print("Simulation OK")
    #Close Dymola
    dymola.close()
    #Selecting result file
    sim = SimRes(
        "/home/manuelnvro/dev/Gitted/PythonTesting/WorkingDir/Dymola/EXAC1.mat"
    )
    #Selecting Variables
    variables = [