setTimeIndex.H
Go to the documentation of this file.
1 {
2  instantList sourceTimes = runTimeSource.times();
3 
4  if (sourceTimes.empty())
5  {
6  FatalErrorInFunction << "No result times in source "
7  << runTimeSource.caseName()
8  << exit(FatalError);
9  }
10 
11  label sourceTimeIndex = runTimeSource.timeIndex();
12  if (args.optionFound("sourceTime"))
13  {
14  if (args["sourceTime"] == "latestTime")
15  {
16  sourceTimeIndex = sourceTimes.size() - 1;
17  }
18  else
19  {
20  sourceTimeIndex = Time::findClosestTimeIndex
21  (
22  sourceTimes,
23  args.optionRead<scalar>("sourceTime")
24  );
25  }
26  }
27  else
28  {
29  sourceTimeIndex = Time::findClosestTimeIndex
30  (
31  sourceTimes,
32  runTimeTarget.time().value()
33  );
34  }
35 
36  runTimeSource.setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex);
37 
38  Info<< "\nSource time: " << runTimeSource.value()
39  << "\nTarget time: " << runTimeTarget.value()
40  << endl;
41 }
List< instant > instantList
List of instants.
Definition: instantList.H:42
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
Time runTimeTarget(Time::controlDictName, args)
Time runTimeSource(Time::controlDictName, argsSrc)
T optionRead(const word &opt) const
Read a value from the named option.
Definition: argListI.H:193
messageStream Info
Foam::argList args(argc, argv)