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