1 """
2 Application-class that implements pyFoamCopyLastToFirst.py
3 """
4
5 from PyFoamApplication import PyFoamApplication
6
7 from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
8 from PyFoam.RunDictionary.TimeDirectory import TimeDirectory
9
10 from PyFoam.Error import error
11
14 description="""
15 Copies the contents of the last time-step of the source case to the
16 first time-step of the destination case (thus using it as initial
17 conditions)
18
19 Whether or not the data fits the destination case is not the problem
20 of this script"""
21 PyFoamApplication.__init__(self,
22 args=args,
23 description=description,
24 usage="%prog [options] <source caseDirectory> <destination caseDirectory>",
25 interspersed=True,
26 changeVersion=False,
27 nr=2)
28
30 self.parser.add_option("--no-overwrite",
31 action="store_false",
32 dest="overwrite",
33 default=True,
34 help="Don't overwrite fields that are already present")
35 self.parser.add_option("--must-exist",
36 action="store_true",
37 dest="mustExist",
38 default=False,
39 help="Only copy fields if they already exist in the destination")
40 self.parser.add_option("--purge",
41 action="store_true",
42 dest="purge",
43 default=False,
44 help="Remove all files in the destination directory before running")
45 self.parser.add_option("--exclude",
46 action="append",
47 default=None,
48 dest="exclude",
49 help="Patterns of files that should be excluded from copying")
50 self.parser.add_option("--include",
51 action="append",
52 default=None,
53 dest="include",
54 help="Patterns of files that should be include from copying (default is all. If this option is set ONLY the specified files will be copied)")
55 self.parser.add_option("--silent",
56 action="store_false",
57 dest="verbose",
58 default=True,
59 help="Don't do any output")
60
62 if len(self.parser.getArgs())!=2:
63 error("Need two arguments.",len(self.parser.getArgs()),"found")
64
65 sName=self.parser.getArgs()[0]
66 dName=self.parser.getArgs()[1]
67
68 if self.opts.include==None:
69 include=["*"]
70 else:
71 include=self.opts.include
72
73 if self.opts.exclude==None:
74 exclude=[]
75 else:
76 exclude=self.opts.exclude
77
78 source=SolutionDirectory(sName,archive=None,paraviewLink=False)
79 dest=SolutionDirectory(dName,archive=None,paraviewLink=False)
80
81 sDir=source[-1]
82 dDir=dest[0]
83
84 if self.opts.verbose:
85 print " Copying from source-time",sDir.baseName(),"to destination-time",dDir.baseName()
86
87 copied=dDir.copy(sDir,
88 include=include,exclude=exclude,
89 overwrite=self.opts.overwrite,
90 mustExist=self.opts.mustExist,
91 purge=self.opts.purge)
92
93 if self.opts.verbose:
94 if len(copied)>0:
95 print " Copied the fields",
96 for v in copied:
97 print v,
98 print
99 else:
100 print " Nothing copied"
101
102 self.addToCaseLog(dest.name,"From",sDir.name,"to",dDir.name)
103