~ubuntu-branches/ubuntu/precise/code-saturne/precise

« back to all changes in this revision

Viewing changes to bin/cs_check_mesh.py

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-24 00:00:08 UTC
  • mfrom: (6.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20111124000008-2vo99e38267942q5
Tags: 2.1.0-3
Install a missing file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#-------------------------------------------------------------------------------
2
 
#   This file is part of the Code_Saturne Solver.
3
 
#
4
 
#   Copyright (C) 2009  EDF
5
 
#
6
 
#   The Code_Saturne Preprocessor is free software; you can redistribute it
7
 
#   and/or modify it under the terms of the GNU General Public License
8
 
#   as published by the Free Software Foundation; either version 2 of
9
 
#   the License, or (at your option) any later version.
10
 
#
11
 
#   The Code_Saturne Preprocessor is distributed in the hope that it will be
12
 
#   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13
 
#   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
#   GNU General Public License for more details.
15
 
#
16
 
#   You should have received a copy of the GNU General Public Licence
17
 
#   along with the Code_Saturne Preprocessor; if not, write to the
18
 
#   Free Software Foundation, Inc.,
19
 
#   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
 
#-------------------------------------------------------------------------------
21
 
 
22
 
import optparse
23
 
import os, re
24
 
import sys, shutil
25
 
import string
26
 
import tempfile
27
 
 
28
 
import cs_config
29
 
 
30
 
from cs_exec_environment import run_command
31
 
 
32
 
#-------------------------------------------------------------------------------
33
 
 
34
 
def subst_name(s):
35
 
 
36
 
    s_up = string.upper(s)
37
 
 
38
 
    stdgeomfile = 'chr.geo'
39
 
    stdcasefile = 'CHR.case'
40
 
 
41
 
    geomfile = s + '.geo'
42
 
    casefile = s_up + '.case'
43
 
 
44
 
    fd = file(stdcasefile, 'r')
45
 
    fdt = file(casefile, 'w')
46
 
    kwd = re.compile('chr.geo')
47
 
    for line in fd:
48
 
        line = re.sub(kwd, s+'.geo', line)
49
 
        fdt.write(line)
50
 
    fd.close()
51
 
    fdt.close()
52
 
 
53
 
    os.remove(stdcasefile)
54
 
    shutil.move(stdgeomfile, geomfile)
55
 
 
56
 
 
57
 
#-------------------------------------------------------------------------------
58
 
 
59
 
def run_check(opts):
60
 
    """
61
 
    Run Code_Saturne preprocessor and solver.
62
 
    """
63
 
    retval = 0
64
 
 
65
 
    cur_dir = os.getcwd()
66
 
 
67
 
    cmd = os.path.join(cs_config.dirs.ecs_bindir, 'cs_preprocess')
68
 
 
69
 
    for o in ('-h', '--help'):
70
 
        if o in opts:
71
 
            cmd = cmd + " " + str(o)
72
 
            retval = run_command(cmd)
73
 
            return retval
74
 
 
75
 
    for o in opts:
76
 
        cmd = cmd + " " + str(o)
77
 
    cmd = cmd + " --ensight --case check_mesh"
78
 
    retval = run_command(cmd)
79
 
 
80
 
    os.chdir('check_mesh.ensight')
81
 
    subst_name('preprocessor')
82
 
    os.chdir(cur_dir)
83
 
 
84
 
 
85
 
    retval = 0
86
 
 
87
 
    cmd = os.path.join(cs_config.dirs.bindir, 'cs_solver')
88
 
    cmd = cmd + " --quality --log 0"
89
 
    retval = run_command(cmd)
90
 
 
91
 
    dir_files = os.listdir('chr.ensight')
92
 
    for f in dir_files:
93
 
        shutil.move(os.path.join('chr.ensight',f), 'check_mesh.ensight')
94
 
    os.rmdir('chr.ensight')
95
 
 
96
 
    os.chdir('check_mesh.ensight')
97
 
    subst_name('quality')
98
 
    os.chdir(cur_dir)
99
 
 
100
 
 
101
 
    os.remove('preprocessor_output')
102
 
 
103
 
    return retval
104
 
 
105
 
#-------------------------------------------------------------------------------
106
 
 
107
 
def main(argv):
108
 
    """
109
 
    Main function.
110
 
    """
111
 
 
112
 
    retcode = run_check(argv)
113
 
    sys.exit(retcode)
114
 
 
115
 
 
116
 
if __name__ == '__main__':
117
 
    main(sys.argv[1:])