-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
333 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
.vscode | ||
__pycache__ | ||
releases | ||
.vscode/ | ||
__pycache__/ | ||
dummy | ||
/releases/ | ||
/examples/* | ||
!/examples/*.inp | ||
!/examples/*.unv | ||
!/examples/*.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
""" © Ihor Mirzov, January 2020 | ||
Distributed under GNU General Public License v3.0 | ||
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') | ||
|
||
|
||
# Recursively delete cached files in all subfolders | ||
def cache(folder=None): | ||
if not folder: | ||
folder = os.getcwd() | ||
pycache = os.path.join(folder, '__pycache__') | ||
if os.path.isdir(pycache): | ||
shutil.rmtree(pycache) # works in Linux as in Windows | ||
|
||
# Recursively clear cache in child folders | ||
for f in os.scandir(folder): | ||
if f.is_dir(): | ||
cache(f.path) | ||
|
||
|
||
# Cleaup trash files in startFolder and all subfolders | ||
def files(startFolder=None): | ||
extensions = ( '.12d', '.cvg', '.dat', '.vwf', '.out', '.nam', '.inp1', '.inp2', | ||
'.sta', '.equ', '.eig', '.stm', '.mtx', '.net', '.inp0', '.rin', | ||
'.fcv', 'dummy' ) | ||
if not startFolder: | ||
startFolder = os.getcwd() | ||
for f in os.scandir(startFolder): | ||
if f.is_dir(): # if folder | ||
files(f.path) | ||
elif f.is_file() and f.name.endswith(extensions): | ||
try: | ||
os.remove(f.path) | ||
sys.__stdout__.write('Delelted: ' + f.path + '\n') | ||
except: | ||
sys.__stdout__.write(f.path + ': ' + sys.exc_info()[1][1] + '\n') | ||
|
||
|
||
# Cleaup old result files | ||
def results(): | ||
extensions = ('.frd', '.vtk', '.vtu') | ||
for f in os.scandir('.'): | ||
if f.name.endswith(extensions): | ||
try: | ||
os.remove(f.path) | ||
sys.__stdout__.write('Delelted: ' + f.path + '\n') | ||
except: | ||
sys.__stdout__.write(f.path + ': ' + sys.exc_info()[1][1] + '\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
""" © Ihor Mirzov, July 2020 | ||
Distributed under GNU General Public License v3.0 | ||
Converts UNV file from Salome to CalculiX INP mesh: | ||
python3 ./src/unv2ccx.py ./examples/116.unv | ||
Reads UNV_file, creates an internal FEM object, | ||
then writes the INP_file. """ | ||
|
||
import os | ||
import sys | ||
import argparse | ||
import logging | ||
|
||
sys.path.append('.') | ||
from src import clean | ||
from src import UNVParser | ||
from src import INPWriter | ||
|
||
|
||
class Converter: | ||
|
||
def __init__(self, unv_file_name): | ||
self.unv_file_name = os.path.normpath(unv_file_name) | ||
self.inp_file_name = self.unv_file_name[:-4]+'.inp' | ||
|
||
def run(self): | ||
|
||
# Parse UNV file | ||
relpath = os.path.relpath(self.unv_file_name, | ||
start=os.path.dirname(__file__)) | ||
logging.info('Parsing ' + relpath) | ||
fem = UNVParser.UNVParser(self.unv_file_name).parse() | ||
|
||
# Write INP file | ||
relpath = os.path.relpath(self.inp_file_name, | ||
start=os.path.dirname(__file__)) | ||
logging.info('Writing ' + relpath) | ||
INPWriter.write(fem, self.inp_file_name) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
# Configure logging | ||
logging.basicConfig(level=logging.INFO, | ||
format='%(levelname)s: %(message)s') | ||
|
||
# Command line parameters | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('filename', type=str, | ||
help='UNV file name with extension') | ||
args = parser.parse_args() | ||
|
||
# Create converter and run it | ||
unv2ccx = Converter(args.filename) | ||
unv2ccx.run() | ||
|
||
clean.cache() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
""" © Ihor Mirzov, June 2020 | ||
Distributed under GNU General Public License v3.0 | ||
Logging handler for all my projects """ | ||
|
||
import os | ||
import sys | ||
import logging | ||
|
||
|
||
log_file = os.path.join(os.path.dirname(__file__), 'test.log') | ||
|
||
|
||
# Configure logging to emit messages via 'print' method | ||
class myHandler(logging.Handler): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.setFormatter(logging.Formatter('%(levelname)s: %(message)s')) | ||
|
||
# Remove old log file | ||
if os.path.isfile(log_file): | ||
os.remove(log_file) | ||
|
||
def emit(self, LogRecord): | ||
print(self.format(LogRecord)) | ||
|
||
|
||
# Redefine print method to write logs to file | ||
def print(*args): | ||
line = ' '.join([str(arg) for arg in args]) | ||
line = line.rstrip() + '\n' | ||
with open(log_file, 'a') as f: | ||
f.write(line) | ||
sys.stdout.write(line) |
Oops, something went wrong.