~reducedmodelling/fluidity/ROM_Non-intrusive-ann

« back to all changes in this revision

Viewing changes to bin/vtudiff

  • Committer: fangf at ac
  • Date: 2012-11-06 12:21:31 UTC
  • mto: This revision was merged to the branch mainline in revision 3989.
  • Revision ID: fangf@imperial.ac.uk-20121106122131-u2zvt7fxc1r3zeou
updated

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# James Maddison
 
4
 
 
5
import getopt
 
6
import sys
 
7
 
 
8
try:
 
9
  import psyco
 
10
  psyco.full()
 
11
except:
 
12
  pass
 
13
 
 
14
import vtktools
 
15
 
 
16
def EPrint(message):
 
17
  """
 
18
  Send an error message to standard error
 
19
  """
 
20
 
 
21
  sys.stderr.write(message + "\n")
 
22
  sys.stderr.flush()
 
23
 
 
24
  return
 
25
 
 
26
def Help():
 
27
  """
 
28
  Prints program usage information
 
29
  """
 
30
 
 
31
  print "Usage: vtudiff [OPTIONS] ... INPUT1 INPUT2 OUTPUT [FIRST] [LAST]\n" + \
 
32
        "\n" + \
 
33
        "Generates vtus with fields equal to the difference between the corresponding\n" + \
 
34
        "fields in two input vtus (INPUT1 - INPUT2). The fields of INPUT2 are projected\n" + \
 
35
        "onto the cell points of INPUT1.\n" + \
 
36
        "\n" + \
 
37
        "If FIRST is supplied, treats INPUT1 and INPUT2 as project names, and generates\n" + \
 
38
        "a different vtu for the specified range of output files.\n" + \
 
39
        "\n" + \
 
40
        "Options:\n" + \
 
41
        "\n" + \
 
42
        "-s  If supplied together with FIRST and LAST, only INPUT1 is treated as a\n" + \
 
43
        "    project name. Allows a range of vtus to be diffed against a single vtu."
 
44
 
 
45
  return
 
46
 
 
47
def Error(message, displayHelp = True):
 
48
  """
 
49
  Print an error message, usage information and quit
 
50
  """
 
51
 
 
52
  if displayHelp:
 
53
    Help()
 
54
 
 
55
  EPrint(message)
 
56
  sys.exit(1)
 
57
 
 
58
try:
 
59
  opts, args = getopt.getopt(sys.argv[1:], "ms")
 
60
except:
 
61
  Help()
 
62
  sys.exit(1)
 
63
 
 
64
if len(args) > 5:
 
65
  Error("Invalid argument \"" + args[5] + "\" supplied")
 
66
 
 
67
diffAgainstSingle = ("-s", "") in opts
 
68
 
 
69
try:
 
70
  inputFilename1 = args[0]
 
71
  inputFilename2 = args[1]
 
72
  outputFilename = args[2]
 
73
except:
 
74
  Help()
 
75
  sys.exit(1)
 
76
 
 
77
if len(args) > 3:
 
78
  try:
 
79
    firstId = int(args[3])
 
80
    if len(args) > 4:
 
81
      try:
 
82
        lastId = int(args[4])
 
83
      except:
 
84
        Error("Invalid last ID entered")
 
85
    else:
 
86
      lastId = firstId
 
87
  except:
 
88
    Error("Invalid first ID entered")
 
89
else:
 
90
  firstId = None
 
91
 
 
92
if firstId is None:
 
93
  inputFilenames1 = [inputFilename1]
 
94
  inputFilenames2 = [inputFilename2]
 
95
  outputFilenames = [outputFilename]
 
96
else:
 
97
  inputFilenames1 = [inputFilename1 + "_" + str(i) + ".vtu" for i in range(firstId, lastId + 1)]
 
98
  if diffAgainstSingle:
 
99
    inputFilenames2 = [inputFilename2 for i in range(firstId, lastId + 1)]
 
100
  else:
 
101
    inputFilenames2 = [inputFilename2 + "_" + str(i) + ".vtu" for i in range(firstId, lastId + 1)]
 
102
 
 
103
  outputFilenames = [outputFilename + "_" + str(i) + ".vtu" for i in range(firstId, lastId + 1)]
 
104
 
 
105
for i in range(len(inputFilenames1)):
 
106
  try:
 
107
    vtu1 = vtktools.vtu(inputFilenames1[i])
 
108
  except:
 
109
    Error("Unable to read input vtu \"" + inputFilenames1[i] + "\"", False)
 
110
  try:
 
111
    vtu2 = vtktools.vtu(inputFilenames2[i])
 
112
  except:
 
113
    Error("Unable to read input vtu \"" + inputFilenames2[i] + "\"", False)
 
114
 
 
115
  diffVtu = vtktools.VtuDiff(vtu1, vtu2, outputFilenames[i])
 
116
 
 
117
  try:
 
118
    diffVtu.Write()
 
119
  except:
 
120
    Help()
 
121
    Error("Unable to write output file \"" + outputFilenames[i] + "\"", False)
 
122
 
 
123
  print "Generated vtu diff file \"" + outputFilenames[i] + "\""