FEM: Add simple dat file reader
It's a simple CalculiX dat file reader used to extract eigenmode frequencies after freqyency analysis. Signed-off-by: Przemo Firszt <przemo@firszt.eu>
This commit is contained in:
parent
3e20529210
commit
30e2ec315b
|
@ -69,6 +69,7 @@ SOURCE_GROUP("Module" FILES ${Mod_SRCS})
|
|||
|
||||
SET(FemScripts_SRCS
|
||||
convert2TetGen.py
|
||||
ccxDatReader.py
|
||||
ccxFrdReader.py
|
||||
ccxInpWriter.py
|
||||
TestFem.py
|
||||
|
|
|
@ -10,6 +10,7 @@ INSTALL(
|
|||
Init.py
|
||||
InitGui.py
|
||||
convert2TetGen.py
|
||||
ccxDatReader.py
|
||||
ccxFrdReader.py
|
||||
ccxInpWriter.py
|
||||
FemTools.py
|
||||
|
|
89
src/Mod/Fem/ccxDatReader.py
Normal file
89
src/Mod/Fem/ccxDatReader.py
Normal file
|
@ -0,0 +1,89 @@
|
|||
#***************************************************************************
|
||||
#* Copyright (c) 2015 - FreeCAD Developers *
|
||||
#* Author: Przemo Firszt <przemo@firszt.eu> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
|
||||
import FreeCAD
|
||||
import os
|
||||
|
||||
__title__ = "ccxDatReader"
|
||||
__author__ = "Przemo Firszt"
|
||||
__url__ = "http://www.freecadweb.org"
|
||||
|
||||
|
||||
if open.__module__ == '__builtin__':
|
||||
# because we'll redefine open below
|
||||
pyopen = open
|
||||
|
||||
EIGENVALUE_OUTPUT_SECTION = " E I G E N V A L U E O U T P U T"
|
||||
|
||||
|
||||
# read a calculix result file and extract the data
|
||||
def readResult(dat_input):
|
||||
dat_file = pyopen(dat_input, "r")
|
||||
eigenvalue_output_section_found = False
|
||||
mode_reading = False
|
||||
results = []
|
||||
|
||||
for line in dat_file:
|
||||
if EIGENVALUE_OUTPUT_SECTION in line:
|
||||
# Found EIGENVALUE_OUTPUT_SECTION
|
||||
eigenvalue_output_section_found = True
|
||||
if eigenvalue_output_section_found:
|
||||
try:
|
||||
mode = int(line[0:7])
|
||||
mode_frequency = float(line[39:55])
|
||||
m = {}
|
||||
m['eigenmode'] = mode
|
||||
m['frequency'] = mode_frequency
|
||||
results.append(m)
|
||||
mode_reading = True
|
||||
except:
|
||||
if mode_reading:
|
||||
# Conversion error after mode reading started, so it's the end of section
|
||||
eigenvalue_output_section_found = False
|
||||
mode_reading = False
|
||||
|
||||
dat_file.close()
|
||||
return results
|
||||
|
||||
|
||||
def import_dat(filename, Analysis=None):
|
||||
r = readResult(filename)
|
||||
#print ("Results {}".format(r))
|
||||
return r
|
||||
|
||||
|
||||
def insert(filename, docname):
|
||||
"called when freecad wants to import a file"
|
||||
try:
|
||||
doc = FreeCAD.getDocument(docname)
|
||||
except NameError:
|
||||
doc = FreeCAD.newDocument(docname)
|
||||
FreeCAD.ActiveDocument = doc
|
||||
|
||||
import_dat(filename)
|
||||
|
||||
|
||||
def open(filename):
|
||||
"called when freecad opens a file"
|
||||
docname = os.path.splitext(os.path.basename(filename))[0]
|
||||
insert(filename, docname)
|
Loading…
Reference in New Issue
Block a user