27         "name of the variable to get time-series from");
 
   32         "type of the variable, can be either scalar or vector");
 
   37         "type of the field variable, can be either volume or surface");
 
   42         "if the fieldType=surface, we need to prescribe the name of the patch");
 
   46         "fieldRefStdTimeSeries",
 
   47         "name of the output file (optional)");
 
   52         "Use user-prescribed deltaT to extract time series, otherwise, use the deltaT in controlDict");
 
   54 #include "setRootCase.H" 
   55 #include "createTime.H" 
   56 #include "createMesh.H" 
   58     word outputName = 
"fieldRefStdTimeSeries";
 
   59     if (
args.optionFound(
"outputName"))
 
   61         outputName = word(
args.optionLookup(
"outputName")());
 
   65     if (
args.optionFound(
"varName"))
 
   67         varName = word(
args.optionLookup(
"varName")());
 
   71         Info << 
"Error: varName not set! Exit." << endl;
 
   75     word varRefName = varName + 
"Data";
 
   78     if (
args.optionFound(
"varType"))
 
   80         varType = word(
args.optionLookup(
"varType")());
 
   84         Info << 
"Error: varType not set! Exit." << endl;
 
   89     if (
args.optionFound(
"fieldType"))
 
   91         fieldType = word(
args.optionLookup(
"fieldType")());
 
   95         Info << 
"Error: fieldType not set! Exit." << endl;
 
  100     if (fieldType == 
"surface")
 
  102         if (
args.optionFound(
"patchName"))
 
  104             patchName = word(
args.optionLookup(
"patchName")());
 
  108             Info << 
"Error: patchName not set! Exit." << endl;
 
  113     OFstream f(outputName + 
".txt");
 
  115     scalar endTime = 
runTime.endTime().value();
 
  116     scalar deltaT = 
runTime.deltaT().value();
 
  118     if (
args.optionFound(
"deltaT"))
 
  120         deltaT = readScalar(
args.optionLookup(
"deltaT")());
 
  122     Info << 
"Extracting " << fieldType << 
" time series for " << varName << endl;
 
  124     label nSteps = round(endTime / deltaT);
 
  126     for (label i = 0; i < nSteps; i++)
 
  128         word timeName = Foam::name((i + 1) * deltaT);
 
  130         if (varType == 
"vector")
 
  141             volVectorField varRef(
 
  150             vector std = vector::zero;
 
  152             if (fieldType == 
"volume")
 
  157                     for (label compI = 0; compI < 3; compI++)
 
  159                         std[compI] += (var[cellI][compI] - varRef[cellI][compI]) * (var[cellI][compI] - varRef[cellI][compI]);
 
  163                 for (label compI = 0; compI < 3; compI++)
 
  165                     std[compI] = Foam::sqrt(std[compI] / 
mesh.nCells());
 
  168             else if (fieldType == 
"surface")
 
  170                 label patchI = 
mesh.boundaryMesh().findPatchID(patchName);
 
  173                     Info << 
"Error. The prescribed patchName " << patchName << 
" not found in constant/polyMesh/boundary" << endl;
 
  175                 label nFaces = var.boundaryField()[patchI].size();
 
  176                 forAll(var.boundaryField()[patchI], faceI)
 
  178                     vector varBC = var.boundaryField()[patchI][faceI];
 
  179                     vector varRefBC = varRef.boundaryField()[patchI][faceI];
 
  181                     for (label compI = 0; compI < 3; compI++)
 
  183                         std[compI] += (varBC[compI] - varRefBC[compI]) * (varBC[compI] - varRefBC[compI]);
 
  187                 for (label compI = 0; compI < 3; compI++)
 
  189                     std[compI] = Foam::sqrt(std[compI] / nFaces);
 
  193             f << std[0] << 
" " << std[1] << 
" " << std[2] << endl;
 
  195         else if (varType == 
"scalar")
 
  206             volScalarField varRef(
 
  217             if (fieldType == 
"volume")
 
  221                     std += (var[cellI] - varRef[cellI]) * (var[cellI] - varRef[cellI]);
 
  224                 std = Foam::sqrt(std / 
mesh.nCells());
 
  226             else if (fieldType == 
"surface")
 
  228                 label patchI = 
mesh.boundaryMesh().findPatchID(patchName);
 
  231                     Info << 
"Error. The prescribed patchName " << patchName << 
" not found in constant/polyMesh/boundary" << endl;
 
  233                 label nFaces = var.boundaryField()[patchI].size();
 
  234                 forAll(var.boundaryField()[patchI], faceI)
 
  236                     scalar varBC = var.boundaryField()[patchI][faceI];
 
  237                     scalar varRefBC = varRef.boundaryField()[patchI][faceI];
 
  238                     std += (varBC - varRefBC) * (varBC - varRefBC);
 
  241                 std = Foam::sqrt(std / nFaces);
 
  248             Info << 
"Error: varType not valid. Can be either scalar or vector! Exit." << endl;
 
  252     Info << 
"Done! " << endl;