-
Notifications
You must be signed in to change notification settings - Fork 41
/
importCfdResultFoamVTK.py
91 lines (71 loc) · 3.76 KB
/
importCfdResultFoamVTK.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# ***************************************************************************
# * *
# * Copyright (c) 2016 - Qingfeng Xia <qingfeng.xia iesensor.com> *
# * *
# * 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 *
# * *
# ***************************************************************************
"""
python-vtk6, which is built with Qt5, does not work with FreeCAD with Qt4
Adapted from ccxFrdReader.py (Calculix result file *.frd reader)
However, readResult() return: list of {'Time': time_step, "Mesh": mesh_data, "Result": result_set}
Python object Fem::FemResultObjectPython consists of property to hold result data
like Temperature, NodeNumbers, Time, Mesh, also CFD specific fields:
Pressure (StressValues), Velocity(DisplacementVectors), etc
export function is implemented in FEM module in cpp,
automatically detect mechanincal or fluidic result
"""
__title__ = "FreeCAD Cfd OpenFOAM library"
__author__ = "Juergen Riegel, Michael Hindley, Bernd Hahnebach, Qingfeng Xia"
__url__ = "http://www.freecadweb.org"
import os
from math import pow, sqrt
import numpy as np
import FreeCAD
if open.__module__ == '__builtin__':
pyopen = open # because we'll redefine open below
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
importCfdResult(filename)
def open(filename):
"called when freecad opens a file"
docname = os.path.splitext(os.path.basename(filename))[0]
insert(filename, docname)
def importCfdResult(filename, analysis=None, result_name_prefix=None):
from CfdObjects import makeCfdResult
import Fem
result_obj = makeCfdResult(result_name_prefix)
if result_name_prefix is None:
result_name_prefix = "CfdResult"
if analysis is None:
analysis_name = os.path.splitext(os.path.basename(filename))[0]
analysis_object = ObjectsFem.makeAnalysis('Analysis')
analysis_object.Label = analysis_name
else:
analysis_object = analysis
analysis_object.Member = analysis_object.Member + [result_obj]
# FIXME move the ResultMesh in the analysis -> call the readReslt after setActiveAnalysis
#Stats has been setup in C++ function Fem.readCfdResult
if(FreeCAD.GuiUp) and analysis:
import FemGui
FemGui.setActiveAnalysis(analysis)
Fem.readResult(filename, result_obj.Name) #always create a new femmesh