2 #-------------------------------------------------------------------------------
4 # | ____| _| |_ / __ \ /\ | \/ |
5 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
6 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
7 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
8 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
10 # FreeFOAM: The Cross-Platform CFD Toolkit
12 # Copyright (C) 2008-2011 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 2 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, write to the Free Software Foundation,
30 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 # Start ParaView with the OpenFOAM plugin
38 #------------------------------------------------------------------------------
40 """Usage: freefoam@PY_SCRIPT_SUFFIX@ para [-case <dir>] [-touch] [-h, -help]
42 Visualize the case <dir> with ParaView.
46 -case <dir> Specify alternative case or processor directory
47 -touch Only create the .foam file
51 # want to be future proof
52 from FreeFOAM
.compat
import *
68 sys
.stderr
.write('Error: The -case option requires an argument\n')
76 sys
.stderr
.write('Error: unknown option/argument "%s"\n'%a
)
77 sys
.stderr
.write(__doc__
+'\n')
80 case
= os
.path
.abspath(case
)
82 # get a sensible caseName
83 caseName
= os
.path
.basename(case
)
84 caseFile
= "%s.foam"%caseName
88 echo('created "%s"'%os.path
.relpath(caseFile
, os
.getcwd()))
91 # parent directory for normal or parallel results
93 if caseName
[:9] == 'processor':
94 parentDir
= os
.path
.dirname(case
)
96 # check existence of essential files
97 for check
in 'controlDict fvSchemes fvSolution'.split():
98 f
= os
.path
.join(parentDir
, 'system', check
)
99 if not os
.path
.isfile(f
):
100 sys
.stderr
.write('Error: File does not exist "%s"\n'%f)
104 if os
.path
.exists(caseFile
):
107 # only create/remove caseFile if it didn't already exist
110 echo('created temporary "%s"'%caseFile
)
112 # Try to find ParaView:
114 if 'FREEFOAM_PARAVIEW_APP' in os
.environ
:
115 # Using a environment variable the user can set...
116 paraview
=os
.environ
['FREEFOAM_PARAVIEW_APP']
117 elif os
.path
.exists('@FOAM_PARAVIEW3_APP@'):
118 # Using the CMake configure value...
119 paraview
="@FOAM_PARAVIEW3_APP@"
121 if not paraview
and os
.uname()[0] == 'Darwin':
122 # On Darwin it might also be an app-bundle
124 if 'FREEFOAM_PARAVIEW_APP' in os
.environ
:
125 pv_dirs
.append(os
.environ
['FREEFOAM_PARAVIEW_APP'])
126 pv_dirs
.extend('/Applications ~/Applications'.split())
128 d
= os
.path
.expanduser(d
)
129 for n
in reversed(glob
.glob(os
.path
.join(d
, '[Pp]ara[Vv]iew*.app'))):
130 tmp
= os
.path
.join(n
, 'Contents', 'MacOS', 'paraview')
131 if os
.path
.isfile(tmp
):
136 # Otherwise notify the user
137 sys
.stderr
.write('Error: Could not find ParaView 3. Either compile it or point\n' +
138 'FREEFOAM_PARAVIEW_APP to the full path of the paraview application.\n')
140 # We want to do nice exit when running paraview to give paraview opportunity
142 if 'FOAM_ABORT' in os
.environ
:
143 del os
.environ
['FOAM_ABORT']
144 sys
.exit(subprocess
.call([paraview
, '--data=%s'%caseFile
]))
149 # ------------------- vim: set sw=3 sts=3 ft=python et: ------------ end-of-file