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