Skip to content

Commit

Permalink
Convenience scripts for #3560
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhard-thiele committed Jan 15, 2016
1 parent c53b470 commit 112f6d9
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitvalidfiles
Expand Up @@ -182,6 +182,7 @@
./simulation/libraries/3rdParty/MathematicalAspects/ReferenceFiles/Test3PhaseSystemsStateSelect.mat
./simulation/libraries/3rdParty/MathematicalAspects/ReferenceFiles/TestSwitch1.mat
./simulation/libraries/3rdParty/MathematicalAspects/ReferenceFiles/TestSwitch2.mat
./simulation/libraries/3rdParty/Modelica_Synchronous/simulateAll.sh
./simulation/libraries/3rdParty/PNlib/ReferenceFiles/PNlib.Examples.Test10.mat
./simulation/libraries/3rdParty/PNlib/ReferenceFiles/PNlib.Examples.Test11.mat
./simulation/libraries/3rdParty/PNlib/ReferenceFiles/PNlib.Examples.Test12.mat
Expand Down
38 changes: 38 additions & 0 deletions simulation/libraries/3rdParty/Modelica_Synchronous/simulateAll.cmd
@@ -0,0 +1,38 @@
@echo off
cls

rem get path to omc
SET OMC=%OPENMODELICAHOME%\bin\omc.exe +locale=C +running-testsuite=dummy.out

rem try to simulate all *.mos files in current folder
for %%f in (*.mos) do (

time /t
echo %%f
%OMC% %%f > %%f.txt 2>&1
rem check the output
if %ERRORLEVEL% NEQ 0 (
echo - translation failed
) else (
if not exist %%~nf_res.mat (
echo - simulation failed
) else (
echo - OK
)
)

rem cleanup the mess
del dummy.out
del *.exe 2>nul 1>&2
del *.c 2>nul 1>&2
del *.h 2>nul 1>&2
del *.libs 2>nul 1>&2
del *.makefile 2>nul 1>&2
del *.mat 2>nul 1>&2
del *.o 2>nul 1>&2
del *.log 2>nul 1>&2
del *.xml 2>nul 1>&2
)

rem sortresults
python sortResults.py > results.txt
26 changes: 26 additions & 0 deletions simulation/libraries/3rdParty/Modelica_Synchronous/simulateAll.sh
@@ -0,0 +1,26 @@
#!/bin/bash
OMC="${OPENMODELICAHOME}/bin/omc +locale=C +running-testsuite=dummy.out +d=hpcom +n=2"
#OMC="${OPENMODELICAHOME}/bin/omc +locale=C +running-testsuite=dummy.out"
echo $OMC
COUNTER=0
for f in *.mos; do
echo $f
$OMC $f > $f.txt 2>&1
ERRORLEVEL=$?

if [ $ERRORLEVEL -ne 0 ]; then
echo "- translation failed"
else
if [ -f ${f}_res.mat ]; then
echo "- simulation failed"
else
echo "- OK"
fi
fi
#COUNTER=$((COUNTER+1))
#if [ $COUNTER -gt 5 ]; then
# break
#fi
done

python sortResults.py > results.txt
169 changes: 169 additions & 0 deletions simulation/libraries/3rdParty/Modelica_Synchronous/sortResults.py
@@ -0,0 +1,169 @@
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: Schubert
#
# Created: 12.11.2012
# Copyright: (c) Schubert 2012
# Licence: <your licence>
#-------------------------------------------------------------------------------

import os
import glob
import shutil

NOGROUP = '_NoGroup'

# GroupName, Words that must occur, Words that must not occur
Groups = [('_Flattening', 'Error occurred while flattening model', None), \
('_Expression', 'Failed to elaborate expression', None), \
('_Nonlinear', 'Error solving nonlinear system', None), \
('_Mixed', 'Your model contains a mixed system involving algorithms', None), \
('_Initialization_convert', 'convertInitialResidualsIntoInitial', None), \
('_Initial_Under', 'It was not possible to solve the under-determined initial system', None), \
('_Initial_Over', 'It was not possible to solve the over-determined initial system', None), \
('_Initial_NotUnique', 'Internal error It is not possible to determine unique', None), \
('_Initialization', 'Error in initialization', None), \
('_Initialization', 'The number of initial equations are not consistent with the number of unfixed variables', None), \
('_Backend', 'Internal error Transformation Module', None), \
('_Backend', 'Internal error IndexReduction.', None), \
('_DivByZero', 'division by zero', None), \
('_CodeGen', 'Error building simulator', None), \
('_Unbalanced', 'Too many equations, overdetermined system', None), \
('_Unbalanced', 'Too few equations, underdetermined system', None), \
('_SimFailed', 'Simulation failed for model', None), \
('_IntegratorFailed', 'Integrator failed', None), \
('_TableBug', ['n Table: NoName from File: NoName with Size', 'try to get', 'out of range!'], None), \
('_SimExecFailed', 'Simulation execution failed for model', None), \
('_UnknownVar', ['Get Data of Var', 'from file', 'failed'], None), \
('_NotEqual', 'Files not Equal!', None), \
('_OK', 'Files Equal!', 'failed')]

def checkFile(fileName, groups):

# Check File Size first (ignore > 128Kb)
if (os.path.getsize(fileName) > 128*1024):
print "Skipping %s. Because file is too large!"%fileName
return NOGROUP

# Open, Read and Close file
f = open(fileName, 'r')
content = f.read()
f.close()

# run through all groups
for g in groups:
groupName = g[0]
include = g[1]
exclude = g[2]
if (include is None): include = list()
if (not isinstance(include, (list,tuple))): include = [include]
if (exclude is None): exclude = list()
if (not isinstance(exclude, (list,tuple))): exclude = [exclude]

# test for include
found = True
for i in include:
if (content.find(i) < 0):
found = False
break
if (found == False): continue

# test for exclude
found = False
for e in exclude:
if (content.find(e) >= 0):
found = True
break
if (found == True): continue

# we found the group
return groupName

# we did not find a matching group
return None

def main():

stat = dict()
models = dict()

# set up folders
if (os.path.exists(NOGROUP)):
shutil.rmtree(NOGROUP)
os.mkdir(NOGROUP)

for g in Groups:
groupName = g[0]
pathName = os.path.join(os.curdir, groupName)
if (os.path.exists(pathName)):
shutil.rmtree( pathName )
os.mkdir( pathName )

# get all ".mos.txt" files in folder
files = glob.glob( os.path.join(os.curdir, '*.mos.txt') )
for fileName in files:

# get group for file
groupName = checkFile(fileName, Groups)

# no group found
if groupName is None: groupName = NOGROUP

# copy file to group
splitName = os.path.split(fileName)
path = os.path.join(os.curdir, groupName)
newFileName = os.path.join(path,splitName[1])
shutil.copyfile(fileName, newFileName)

# count
try:
stat[groupName] = stat[groupName] + 1
except:
stat[groupName] = 1

# log
try:
models[groupName].append(splitName[1])
except:
models[groupName] = [splitName[1]]

# delete folders if empty
for g in Groups:
groupName = g[0]
pathName = os.path.join(os.curdir, groupName)
if (not (groupName in stat.keys())) and (os.path.exists(pathName)):
os.rmdir( pathName )


# Finished
print "**** Statistics ****"
print "%i models in total"%len(files)
for k,v in sorted(stat.items()):
groupName = k.replace('_', '')
print "%s:\t%i"%(groupName,v)


print "\n**** Details - groupwise ****"
for k,v in sorted(models.items()):
groupName = k.replace('_', '')
print "%s (%i):"%(groupName, len(v))
for m in sorted(v):
modelName = m.replace('.mos.txt', '')
print "\t%s"%modelName

# Inverse Mapping
inv_map = {}
for k, v in models.iteritems():
groupName = k.replace('_', '')
for m in v:
modelName = m.replace('.mos.txt', '')
inv_map[modelName] = groupName

print "\n**** Details - modelwise ****"
for k,v in sorted(inv_map.items()):
print "%s -> %s"%(k, v)

if __name__ == '__main__':
main()

0 comments on commit 112f6d9

Please sign in to comment.