2 #-------------------------------------------------------------------------------
4 # | ____| _| |_ / __ \ /\ | \/ |
5 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
6 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
7 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
8 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
10 # FreeFOAM: The Cross-Platform CFD Toolkit
12 # Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
13 # Gerber van der Graaf <gerber_graaf@users.sf.net>
14 #-------------------------------------------------------------------------------
16 # This file is part of FreeFOAM.
18 # FreeFOAM is free software: you can redistribute it and/or modify it
19 # under the terms of the GNU General Public License as published by the
20 # Free Software Foundation, either version 3 of the License, or (at your
21 # option) any later version.
23 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
24 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 # You should have received a copy of the GNU General Public License
29 # along with FreeFOAM. If not, see <http://www.gnu.org/licenses/>.
35 # Start ParaView with the OpenFOAM plugin
37 #------------------------------------------------------------------------------
39 """Usage: freefoam@PY_SCRIPT_SUFFIX@ para [-case <dir>] [-touch] [-h, -help]
41 Visualize the case <dir> with ParaView.
45 -case <dir> Specify alternative case or processor directory
46 -touch Only create the .foam file
55 # want to be future proof
56 sys
.path
.insert(0, '@FOAM_PYTHON_DIR@')
57 from FreeFOAM
.compat
import *
67 sys
.stderr
.write('Error: The -case option requires an argument\n')
75 sys
.stderr
.write('Error: unknown option/argument "%s"\n'%a
)
76 sys
.stderr
.write(__doc__
+'\n')
79 case
= os
.path
.abspath(case
)
81 # get a sensible caseName
82 caseName
= os
.path
.basename(case
)
83 caseFile
= "%s.foam"%caseName
87 echo('created "%s"'%os.path
.relpath(caseFile
, os
.getcwd()))
90 # parent directory for normal or parallel results
92 if caseName
[:9] == 'processor':
93 parentDir
= os
.path
.dirname(case
)
95 # check existence of essential files
96 for check
in 'controlDict fvSchemes fvSolution'.split():
97 f
= os
.path
.join(parentDir
, 'system', check
)
98 if not os
.path
.isfile(f
):
99 sys
.stderr
.write('Error: File does not exist "%s"\n'%f)
103 if os
.path
.exists(caseFile
):
106 # only create/remove caseFile if it didn't already exist
109 echo('created temporary "%s"'%caseFile
)
111 # Try to find ParaView:
113 if 'FREEFOAM_PARAVIEW_APP' in os
.environ
:
114 # Using a environment variable the user can set...
115 paraview
=os
.environ
['FREEFOAM_PARAVIEW_APP']
116 elif os
.path
.exists('@FOAM_PARAVIEW3_APP@'):
117 # Using the CMake configure value...
118 paraview
="@FOAM_PARAVIEW3_APP@"
120 if not paraview
and os
.uname()[0] == 'Darwin':
121 # On Darwin it might also be an app-bundle
123 if 'FREEFOAM_PARAVIEW_APP' in os
.environ
:
124 pv_dirs
.append(os
.environ
['FREEFOAM_PARAVIEW_APP'])
125 pv_dirs
.extend('/Applications ~/Applications'.split())
127 d
= os
.path
.expanduser(d
)
128 for n
in reversed(glob
.glob(os
.path
.join(d
, '[Pp]ara[Vv]iew*.app'))):
129 tmp
= os
.path
.join(n
, 'Contents', 'MacOS', 'paraview')
130 if os
.path
.isfile(tmp
):
135 # Otherwise notify the user
136 sys
.stderr
.write('Error: Could not find ParaView 3. Either compile it or point\n' +
137 'FREEFOAM_PARAVIEW_APP to the full path of the paraview application.\n')
139 # We want to do nice exit when running paraview to give paraview opportunity
141 if 'FOAM_ABORT' in os
.environ
:
142 del os
.environ
['FOAM_ABORT']
143 sys
.exit(subprocess
.call([paraview
, '--data=%s'%caseFile
]))
148 # ------------------- vim: set sw=3 sts=3 ft=python et: ------------ end-of-file