Skip to content

Commit

Permalink
Release v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
imirzov committed May 11, 2020
1 parent e36b35e commit 13a6132
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 54 deletions.
16 changes: 5 additions & 11 deletions INPWriter.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# -*- coding: utf-8 -*-


"""
© Joël Cugnoni, September 2006 - original code, www.caelinux.com
© Ihor Mirzov, August 2019 - refactoring
Distributed under GNU General Public License v3.0
Writes FEM nodes, elements and groups (node and element sets) into INP file.
"""
© Joël Cugnoni, September 2006 - original code, www.caelinux.com
© Ihor Mirzov, August 2019 - refactoring
Distributed under GNU General Public License v3.0
Writes FEM nodes, elements and groups
(node and element sets) into INP file. """

import os, logging, re
PADDING = ' '*4 # four spaces


# Main function
def write(FEM, filename):

Expand Down Expand Up @@ -62,7 +59,6 @@ def write(FEM, filename):
f.write('*ELSET, ELSET=' + group.name)
writeGroup(f, group)


# Write node or element set
def writeGroup(f, group):
for i in range(group.nitems):
Expand All @@ -71,7 +67,6 @@ def writeGroup(f, group):
f.write('{:d}, '.format(group.items[i]))
f.write('\n')


# Convert UNV element type to CalculiX
def convert_element(unv_element_type):

Expand Down Expand Up @@ -169,7 +164,6 @@ def convert_element(unv_element_type):
else:
return None


# Map of the nodes between Universal and Calculix elements
def element_connectivity(ccx_element_type):

Expand Down
26 changes: 12 additions & 14 deletions UNVParser.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
# -*- coding: utf-8 -*-


"""
© Joël Cugnoni, September 2006 - original code, www.caelinux.com
© Ihor Mirzov, August 2019 - refactoring
Distributed under GNU General Public License v3.0
© Joël Cugnoni, September 2006 - original code, www.caelinux.com
© Ihor Mirzov, August 2019 - refactoring
Distributed under GNU General Public License v3.0
This is a set of objects & functions to read a Universal File
into a simple FEM object structure in order to simplify the
conversion of Mesh definitions from UNV to any other format.
This is a set of objects & functions to read a Universal File
into a simple FEM object structure in order to simplify the
conversion of Mesh definitions from UNV to any other format.
This code is based on two main objects:
1) FEM object structure to store nodes, elements and groups.
2) UNVParser which provides a simple & modular solution to read
some datasets from UNV file and store them in a FEM object structure.
This code is based on two main objects:
1) FEM object structure to store nodes, elements and groups.
2) UNVParser which provides a simple & modular solution to read
some datasets from UNV file and store them in a FEM object structure.
UNV format documentation:
http://sdrl.uc.edu/sdrl/referenceinfo/universalfileformats/file-format-storehouse/universal-file-datasets-summary
UNV format documentation:
http://sdrl.uc.edu/sdrl/referenceinfo/universalfileformats/file-format-storehouse/universal-file-datasets-summary
"""


import logging, FEM
FLAG = ' -1'

Expand Down
17 changes: 6 additions & 11 deletions clean.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
# -*- coding: utf-8 -*-

""" © Ihor Mirzov, August 2019
Distributed under GNU General Public License v3.0
"""
© Ihor Mirzov, August 2019
Distributed under GNU General Public License v3.0
Routine methods for cleaning up temporary/unused files/folders.
"""


import os, sys, shutil
Routine methods for cleaning up temporary/unused files/folders. """

import os
import sys
import shutil

# Clean screen
def screen():
os.system('cls' if os.name=='nt' else 'clear')


# Delete cached files
def cache():
# os.system('py3clean .')
if os.path.isdir('__pycache__'):
shutil.rmtree('__pycache__') # works in Linux as in Windows


# Cleaup trash files in startFolder and all subfolders
def files(startFolder):
extensions = ( '.12d', '.cvg', '.dat', '.vwf', '.out', '.nam', '.inp1', '.inp2',
Expand Down
84 changes: 84 additions & 0 deletions make_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-

""" © Ihor Mirzov, September 2019
Distributed under GNU General Public License v3.0
Prepare binaries for publishing:
- python3 make_release.py
or 'Ctrl+F5' from VSCode """

import clean
import os
import shutil
import datetime
import PyInstaller.__main__

def copy(src, dst, skip):
for f in os.listdir(src):
if f!='dist' and not f.endswith(skip):
src_path = os.path.join(src, f)
dst_path = os.path.join('dist', src, f)

if os.path.isdir(src_path):
if not os.path.isdir(dst_path):
os.mkdir(dst_path)
copy(src_path, dst_path, skip)

if os.path.isfile(src_path):
shutil.copy2(src_path, dst_path)

if __name__ == '__main__':
if os.name=='nt':
op_sys = '_windows'
extension = '.exe' # binary extension in OS
TEMP = 'C:\\Windows\\Temp\\'
else:
op_sys = '_linux'
extension = '' # binary extension in OS
TEMP = '/tmp/'

skip = (op_sys, )
PROJECT_NAME = os.path.split(os.getcwd())[-1] # name of project's folder
DATE = '_' + datetime.datetime.now().strftime('%Y%m%d')
ARCH = os.path.join('./releases', PROJECT_NAME + DATE + op_sys)

# Remove prev. trash
if os.path.isdir('./dist'):
shutil.rmtree('./dist')

# Run pyinstaller to create binaries
args = [
'./unv2ccx.py',
'--workpath=' + TEMP, # temp dir
'-w', # no console during app run
'--onefile',
]
PyInstaller.__main__.run(args)

# Delete cached files
clean.cache()

# Delete .spec file
if os.path.isfile('unv2ccx.spec'):
os.remove('unv2ccx.spec')

# Prepare skip list
with open('.gitignore', 'r') as f:
lines = f.readlines()
for i in range(len(lines)):
skip += (lines[i].rstrip().lstrip('*'), )
skip += ('.git', '.gitignore', '.py', 'dist')

# Copy files and folders from sources to 'dist'
copy('.', 'dist', skip)

# Make archive
if os.path.isfile(ARCH + '.zip'):
os.remove(ARCH + '.zip') # delete old

# Complress whole directory
shutil.make_archive(ARCH, 'zip', 'dist')

# Remove unneeded files and folders
shutil.rmtree(TEMP + 'unv2ccx')
shutil.rmtree(os.path.abspath('dist'))
15 changes: 8 additions & 7 deletions tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-

"""
© Ihor Mirzov, April 2019
Distributed under GNU General Public License v3.0
""" © Ihor Mirzov, May 2020
Distributed under GNU General Public License v3.0
Usage:
python3 tests.py
"""
Usage:
- python3 tests.py
or 'Ctrl+F5' from VSCode """

import subprocess, os, clean

Expand All @@ -30,7 +29,9 @@ def listAllFiles(startFolder, ext):

# Convert calculation results
for filename in listAllFiles('./tests', '.unv'):
subprocess.run('python3 unv2ccx.py ' + filename, shell=True)
# subprocess.run('python3 unv2ccx.py ' + filename, shell=True)
cmd = 'unv2ccx{} {}'.format(extension, filename)
subprocess.run(cmd, shell=True)
# break # one file only

clean.cache()
Expand Down
17 changes: 6 additions & 11 deletions unv2ccx.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
# -*- coding: utf-8 -*-

""" © Ihor Mirzov, August 2019
Distributed under GNU General Public License v3.0
"""
© Ihor Mirzov, August 2019
Distributed under GNU General Public License v3.0
Converts UNV file from Salome to CalculiX INP mesh: reads UNV_file,
creates an internal FEM object, then writes the INP_file.
Usage:
python3 unv2ccx.py ./tests-elements/116.unv
"""
Converts UNV file from Salome to CalculiX INP mesh: reads UNV_file,
creates an internal FEM object, then writes the INP_file.
Usage:
python3 unv2ccx.py ./tests-elements/116.unv """

import os, argparse, logging, shutil, INPWriter
from UNVParser import *


if __name__ == '__main__':

# Clean cached files
Expand Down

0 comments on commit 13a6132

Please sign in to comment.