externalCoupledFunctionObject.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2015 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
28 #include "OSspecific.H"
29 #include "IFstream.H"
30 #include "OFstream.H"
31 #include "volFields.H"
32 #include "globalIndex.H"
33 #include "fvMesh.H"
34 #include "DynamicField.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(externalCoupledFunctionObject, 0);
41 
43  (
44  functionObject,
45  externalCoupledFunctionObject,
46  dictionary
47  );
48 }
49 
51 
53 
54 
55 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
56 
58 {
59  fileName result(commsDir_);
60  result.clean();
61 
62  return result;
63 }
64 
65 
67 (
68  const fileName& commsDir,
69  const word& regionGroupName,
70  const wordRe& groupName
71 )
72 {
73  fileName result
74  (
75  commsDir
76  /regionGroupName
77  /string::validate<fileName>(groupName)
78  );
79  result.clean();
80 
81  return result;
82 }
83 
84 
86 {
87  return fileName(baseDir()/(lockName + ".lock"));
88 }
89 
90 
92 {
93  if (!Pstream::master())
94  {
95  return;
96  }
97 
98  const fileName fName(lockFile());
99  IFstream is(fName);
100 
101  // Only create lock file if it doesn't already exist
102  if (!is.good())
103  {
104  if (log_) Info<< type() << ": creating lock file" << endl;
105 
106  OFstream os(fName);
107  os << "lock file";
108  os.flush();
109  }
110 }
111 
112 
114 {
115  if (!Pstream::master())
116  {
117  return;
118  }
119 
120  if (log_) Info<< type() << ": removing lock file" << endl;
121 
122  rm(lockFile());
123 }
124 
125 
127 {
128  if (!Pstream::master())
129  {
130  return;
131  }
132 
133  if (log_) Info<< type() << ": removing all read files" << endl;
134 
135  forAll(regionGroupNames_, regionI)
136  {
137  const word& compName = regionGroupNames_[regionI];
138 
139  const labelList& groups = regionToGroups_[compName];
140  forAll(groups, i)
141  {
142  label groupI = groups[i];
143  const wordRe& groupName = groupNames_[groupI];
144 
145  forAll(groupReadFields_[groupI], fieldI)
146  {
147  const word& fieldName = groupReadFields_[groupI][fieldI];
148  rm
149  (
150  groupDir(commsDir_, compName, groupName)
151  / fieldName + ".in"
152  );
153  }
154  }
155  }
156 }
157 
158 
160 {
161  if (!Pstream::master())
162  {
163  return;
164  }
165 
166  if (log_) Info<< type() << ": removing all write files" << endl;
167 
168  forAll(regionGroupNames_, regionI)
169  {
170  const word& compName = regionGroupNames_[regionI];
171 
172  const labelList& groups = regionToGroups_[compName];
173  forAll(groups, i)
174  {
175  label groupI = groups[i];
176  const wordRe& groupName = groupNames_[groupI];
177 
178  forAll(groupReadFields_[groupI], fieldI)
179  {
180  const word& fieldName = groupReadFields_[groupI][fieldI];
181  rm
182  (
183  groupDir(commsDir_, compName, groupName)
184  / fieldName + ".out"
185  );
186  }
187  }
188  }
189 }
190 
191 
193 {
194  const fileName fName(lockFile());
195  label found = 0;
196  label totalTime = 0;
197 
198  if (log_) Info<< type() << ": beginning wait for lock file " << fName << nl;
199 
200  while (found == 0)
201  {
202  if (Pstream::master())
203  {
204  if (totalTime > timeOut_)
205  {
207  << "Wait time exceeded time out time of " << timeOut_
208  << " s" << abort(FatalError);
209  }
210 
211  IFstream is(fName);
212 
213  if (is.good())
214  {
215  found++;
216 
217  if (log_)
218  {
219  Info<< type() << ": found lock file " << fName << endl;
220  }
221  }
222  else
223  {
224  sleep(waitInterval_);
225  totalTime += waitInterval_;
226 
227  if (log_)
228  {
229  Info<< type() << ": wait time = " << totalTime << endl;
230  }
231  }
232  }
233 
234  // prevent other procs from racing ahead
236  }
237 }
238 
239 
241 (
242  const label nRows,
243  const label nColumns,
244  autoPtr<IFstream>& masterFilePtr,
246 ) const
247 {
248  // Get sizes for all processors
249  const globalIndex globalFaces(nRows);
250 
252  if (Pstream::master())
253  {
254  string line;
255 
256  // Read data from file and send to destination processor
257 
258  for (label procI = 0; procI < Pstream::nProcs(); procI++)
259  {
260  // Temporary storage
261  List<scalarField> values(nColumns);
262 
263  // Number of rows to read for processor procI
264  label procNRows = globalFaces.localSize(procI);
265 
266  forAll(values, columnI)
267  {
268  values[columnI].setSize(procNRows);
269  }
270 
271  for (label rowI = 0; rowI < procNRows; rowI++)
272  {
273  // Get a line
274  do
275  {
276  if (!masterFilePtr().good())
277  {
278  FatalIOErrorInFunction(masterFilePtr())
279  << "Trying to read data for processor " << procI
280  << " row " << rowI
281  << ". Does your file have as many rows as there are"
282  << " patch faces (" << globalFaces.size()
283  << ") ?" << exit(FatalIOError);
284  }
285 
286  masterFilePtr().getLine(line);
287  } while (line.empty() || line[0] == '#');
288 
289  IStringStream lineStr(line);
290 
291  for (label columnI = 0; columnI < nColumns; columnI++)
292  {
293  lineStr >> values[columnI][rowI];
294  }
295  }
296 
297  // Send to procI
298  UOPstream str(procI, pBufs);
299  str << values;
300  }
301  }
302  pBufs.finishedSends();
303 
304  // Read from PstreamBuffers
305  UIPstream str(Pstream::masterNo(), pBufs);
306  str >> data;
307 }
308 
309 
311 (
312  const label nRows,
313  autoPtr<IFstream>& masterFilePtr,
314  OStringStream& lines
315 ) const
316 {
317  // Get sizes for all processors
318  const globalIndex globalFaces(nRows);
319 
321 
322  if (Pstream::master())
323  {
324  string line;
325 
326  // Read line from file and send to destination processor
327 
328  for (label procI = 0; procI < Pstream::nProcs(); procI++)
329  {
330  // Number of rows to read for processor procI
331  label procNRows = globalFaces.localSize(procI);
332 
333  UOPstream toProc(procI, pBufs);
334 
335  for (label rowI = 0; rowI < procNRows; rowI++)
336  {
337  // Get a line
338  do
339  {
340  if (!masterFilePtr().good())
341  {
342  FatalIOErrorInFunction(masterFilePtr())
343  << "Trying to read data for processor " << procI
344  << " row " << rowI
345  << ". Does your file have as many rows as there are"
346  << " patch faces (" << globalFaces.size()
347  << ") ?" << exit(FatalIOError);
348  }
349 
350  masterFilePtr().getLine(line);
351  } while (line.empty() || line[0] == '#');
352 
353  // Send line to the destination processor
354  toProc << line;
355  }
356  }
357  }
358 
359 
360  pBufs.finishedSends();
361 
362  // Read lines from PstreamBuffers
363  UIPstream str(Pstream::masterNo(), pBufs);
364  for (label rowI = 0; rowI < nRows; rowI++)
365  {
366  string line(str);
367  lines << line.c_str() << nl;
368  }
369 }
370 
371 
373 (
374  const UPtrList<const fvMesh>& meshes,
375  const fileName& commsDir,
376  const wordRe& groupName
377 )
378 {
379  wordList regionNames(meshes.size());
380  forAll(meshes, i)
381  {
382  regionNames[i] = meshes[i].dbDir();
383  }
384 
385  // Make sure meshes are provided in sorted order
386  checkOrder(regionNames);
387 
388  fileName dir(groupDir(commsDir, compositeName(regionNames), groupName));
389 
390  //if (log_)
391  {
392  Info<< typeName << ": writing geometry to " << dir << endl;
393  }
394 
395  autoPtr<OFstream> osPointsPtr;
396  autoPtr<OFstream> osFacesPtr;
397  if (Pstream::master())
398  {
399  mkDir(dir);
400  osPointsPtr.reset(new OFstream(dir/"patchPoints"));
401  osFacesPtr.reset(new OFstream(dir/"patchFaces"));
402  }
403 
404 
405  DynamicList<face> allMeshesFaces;
406  DynamicField<point> allMeshesPoints;
407 
408  forAll(meshes, meshI)
409  {
410  const fvMesh& mesh = meshes[meshI];
411 
412  const labelList patchIDs
413  (
415  (
416  List<wordRe>(1, groupName)
417  ).sortedToc()
418  );
419 
420  // Count faces
421  label nFaces = 0;
422  forAll(patchIDs, i)
423  {
424  nFaces += mesh.boundaryMesh()[patchIDs[i]].size();
425  }
426 
427  // Collect faces
428  DynamicList<label> allFaceIDs(nFaces);
429  forAll(patchIDs, i)
430  {
431  const polyPatch& p = mesh.boundaryMesh()[patchIDs[i]];
432 
433  forAll(p, pI)
434  {
435  allFaceIDs.append(p.start()+pI);
436  }
437  }
438 
439  // Construct overall patch
440  indirectPrimitivePatch allPatch
441  (
442  IndirectList<face>(mesh.faces(), allFaceIDs),
443  mesh.points()
444  );
445 
446  labelList pointToGlobal;
447  labelList uniquePointIDs;
449  (
450  allPatch.meshPoints(),
451  allPatch.meshPointMap(),
452  pointToGlobal,
453  uniquePointIDs
454  );
455 
456  label procI = Pstream::myProcNo();
457 
458  List<pointField> collectedPoints(Pstream::nProcs());
459  collectedPoints[procI] = pointField(mesh.points(), uniquePointIDs);
460  Pstream::gatherList(collectedPoints);
461 
462  List<faceList> collectedFaces(Pstream::nProcs());
463  faceList& patchFaces = collectedFaces[procI];
464  patchFaces = allPatch.localFaces();
465  forAll(patchFaces, faceI)
466  {
467  inplaceRenumber(pointToGlobal, patchFaces[faceI]);
468  }
469  Pstream::gatherList(collectedFaces);
470 
471  if (Pstream::master())
472  {
473  // Append and renumber
474  label nPoints = allMeshesPoints.size();
475 
476  forAll(collectedPoints, procI)
477  {
478  allMeshesPoints.append(collectedPoints[procI]);
479 
480  }
481  face newFace;
482  forAll(collectedFaces, procI)
483  {
484  const faceList& procFaces = collectedFaces[procI];
485 
486  forAll(procFaces, faceI)
487  {
488  const face& f = procFaces[faceI];
489 
490  newFace.setSize(f.size());
491  forAll(f, fp)
492  {
493  newFace[fp] = f[fp]+nPoints;
494  }
495  allMeshesFaces.append(newFace);
496  }
497 
498  nPoints += collectedPoints[procI].size();
499  }
500  }
501 
502  //if (log_)
503  {
504  Info<< typeName << ": for mesh " << mesh.name()
505  << " writing " << allMeshesPoints.size() << " points to "
506  << osPointsPtr().name() << endl;
507  Info<< typeName << ": for mesh " << mesh.name()
508  << " writing " << allMeshesFaces.size() << " faces to "
509  << osFacesPtr().name() << endl;
510  }
511  }
512 
513  // Write points
514  if (osPointsPtr.valid())
515  {
516  osPointsPtr() << allMeshesPoints << endl;
517  }
518 
519  // Write faces
520  if (osFacesPtr.valid())
521  {
522  osFacesPtr() << allMeshesFaces << endl;
523  }
524 }
525 
526 
528 (
529  const wordList& regionNames
530 )
531 {
532  if (regionNames.size() == 0)
533  {
535  << "Empty regionNames" << abort(FatalError);
536  return word::null;
537  }
538  else if (regionNames.size() == 1)
539  {
540  if (regionNames[0] == polyMesh::defaultRegion)
541  {
542  // For compatibility with single region cases suppress single
543  // region name
544  return word("");
545  }
546  else
547  {
548  return regionNames[0];
549  }
550  }
551  else
552  {
553  // Enforce lexical ordering
554  checkOrder(regionNames);
555 
556  word composite(regionNames[0]);
557  for (label i = 1; i < regionNames.size(); i++)
558  {
559  composite += "_" + regionNames[i];
560  }
561 
562  return composite;
563  }
564 }
565 
566 
568 (
569  const wordList& regionNames
570 )
571 {
572  labelList order;
573  sortedOrder(regionNames, order);
574  if (order != identity(regionNames.size()))
575  {
577  << "regionNames " << regionNames << " not in alphabetical order :"
578  << order << exit(FatalError);
579  }
580 }
581 
582 
584 {
585  forAll(regionGroupNames_, regionI)
586  {
587  const word& compName = regionGroupNames_[regionI];
588  const wordList& regionNames = regionGroupRegions_[regionI];
589 
590  // Get the meshes for the region-group
591  UPtrList<const fvMesh> meshes(regionNames.size());
592  forAll(regionNames, j)
593  {
594  const word& regionName = regionNames[j];
595  meshes.set(j, &time_.lookupObject<fvMesh>(regionName));
596  }
597 
598  const labelList& groups = regionToGroups_[compName];
599 
600  forAll(groups, i)
601  {
602  label groupI = groups[i];
603  const wordRe& groupName = groupNames_[groupI];
604  const wordList& fieldNames = groupReadFields_[groupI];
605 
606  forAll(fieldNames, fieldI)
607  {
608  const word& fieldName = fieldNames[fieldI];
609 
610  bool ok = readData<scalar>
611  (
612  meshes,
613  groupName,
614  fieldName
615  );
616  ok = ok || readData<vector>
617  (
618  meshes,
619  groupName,
620  fieldName
621  );
622  ok = ok || readData<sphericalTensor>
623  (
624  meshes,
625  groupName,
626  fieldName
627  );
628  ok = ok || readData<symmTensor>
629  (
630  meshes,
631  groupName,
632  fieldName
633  );
634  ok = ok || readData<tensor>
635  (
636  meshes,
637  groupName,
638  fieldName
639  );
640 
641  if (!ok)
642  {
644  << "Field " << fieldName << " in regions " << compName
645  << " was not found." << endl;
646  }
647  }
648  }
649  }
650 }
651 
652 
654 {
655  forAll(regionGroupNames_, regionI)
656  {
657  const word& compName = regionGroupNames_[regionI];
658  const wordList& regionNames = regionGroupRegions_[regionI];
659 
660  // Get the meshes for the region-group
661  UPtrList<const fvMesh> meshes(regionNames.size());
662  forAll(regionNames, j)
663  {
664  const word& regionName = regionNames[j];
665  meshes.set(j, &time_.lookupObject<fvMesh>(regionName));
666  }
667 
668  const labelList& groups = regionToGroups_[compName];
669 
670  forAll(groups, i)
671  {
672  label groupI = groups[i];
673  const wordRe& groupName = groupNames_[groupI];
674  const wordList& fieldNames = groupWriteFields_[groupI];
675 
676  forAll(fieldNames, fieldI)
677  {
678  const word& fieldName = fieldNames[fieldI];
679 
680  bool ok = writeData<scalar>
681  (
682  meshes,
683  groupName,
684  fieldName
685  );
686  ok = ok || writeData<vector>
687  (
688  meshes,
689  groupName,
690  fieldName
691  );
692  ok = ok || writeData<sphericalTensor>
693  (
694  meshes,
695  groupName,
696  fieldName
697  );
698  ok = ok || writeData<symmTensor>
699  (
700  meshes,
701  groupName,
702  fieldName
703  );
704  ok = ok || writeData<tensor>
705  (
706  meshes,
707  groupName,
708  fieldName
709  );
710 
711  if (!ok)
712  {
714  << "Field " << fieldName << " in regions " << compName
715  << " was not found." << endl;
716  }
717  }
718  }
719  }
720 }
721 
722 
724 {
725  if (initialised_)
726  {
727  return;
728  }
729 
730  // Write the geometry if not already there
731  forAll(regionGroupRegions_, i)
732  {
733  const word& compName = regionGroupNames_[i];
734  const wordList& regionNames = regionGroupRegions_[i];
735 
736  // Get the meshes for the region-group
737  UPtrList<const fvMesh> meshes(regionNames.size());
738  forAll(regionNames, j)
739  {
740  const word& regionName = regionNames[j];
741  meshes.set(j, &time_.lookupObject<fvMesh>(regionName));
742  }
743 
744  const labelList& groups = regionToGroups_[compName];
745 
746  forAll(groups, i)
747  {
748  label groupI = groups[i];
749  const wordRe& groupName = groupNames_[groupI];
750 
751  bool exists = false;
752  if (Pstream::master())
753  {
754  fileName dir(groupDir(commsDir_, compName, groupName));
755 
756  exists =
757  isFile(dir/"patchPoints")
758  || isFile(dir/"patchFaces");
759  }
760 
761  if (!returnReduce(exists, orOp<bool>()))
762  {
763  writeGeometry(meshes, commsDir_, groupName);
764  }
765  }
766  }
767 
768  if (initByExternal_)
769  {
770  // Wait for initial data to be made available
771  wait();
772 
773  // Eead data passed back from external source
774  readData();
775  }
776 
777  initialised_ = true;
778 }
779 
780 
781 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
782 
784 (
785  const word& name,
786  const Time& runTime,
787  const dictionary& dict
788 )
789 :
791  time_(runTime),
792  enabled_(true),
793  initialised_(false)
794 {
795  read(dict);
796 
797  if (Pstream::master())
798  {
799  mkDir(baseDir());
800  }
801 
802  if (!initByExternal_)
803  {
804  createLockFile();
805  }
806 }
807 
808 
809 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
810 
812 {}
813 
814 
815 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
816 
818 {
819  enabled_ = true;
820 }
821 
822 
824 {
825  enabled_ = false;
826 }
827 
828 
830 {
831  return true;
832 }
833 
834 
836 {
837  if
838  (
839  enabled()
840  && (!initialised_ || time_.timeIndex() % calcFrequency_ == 0)
841  )
842  {
843  // Initialise the coupling
844  initialise();
845 
846  // Write data for external source
847  writeData();
848 
849  // remove lock file, signalling external source to execute
850  removeLockFile();
851 
852  // Wait for response
853  wait();
854 
855  // Remove old data files from OpenFOAM
856  removeWriteFiles();
857 
858  // Read data passed back from external source
859  readData();
860 
861  // create lock file for external source
862  createLockFile();
863 
864  return true;
865  }
866  else
867  {
868  return false;
869  }
870 }
871 
872 
874 {
875  if (enabled())
876  {
877  // Remove old data files
878  removeReadFiles();
879  removeWriteFiles();
880  removeLockFile();
881  }
882 
883  return true;
884 }
885 
886 
888 {
889  // Do nothing - only valid on execute
890  return true;
891 }
892 
893 
895 {
896  return true;
897 }
898 
899 
901 {
902  dict.readIfPresent("enabled", enabled_);
903 
904  if (!enabled_)
905  {
906  return true;
907  }
908 
909  dict.lookup("commsDir") >> commsDir_;
910  commsDir_.expand();
911 
912  waitInterval_ = dict.lookupOrDefault("waitInterval", 1);
913  timeOut_ = dict.lookupOrDefault("timeOut", 100*waitInterval_);
914  calcFrequency_ = dict.lookupOrDefault("calcFrequency", 1);
915  initByExternal_ = readBool(dict.lookup("initByExternal"));
916  log_ = dict.lookupOrDefault("log", false);
917 
918 
919  // Get names of all fvMeshes (and derived types)
920  wordList allRegionNames(time_.lookupClass<fvMesh>().sortedToc());
921 
922 
923 
924  const dictionary& allRegionsDict = dict.subDict("regions");
925 
926  forAllConstIter(dictionary, allRegionsDict, iter)
927  {
928  if (!iter().isDict())
929  {
930  FatalIOErrorInFunction(allRegionsDict)
931  << "Regions must be specified in dictionary format"
932  << exit(FatalIOError);
933  }
934 
935  const wordRe regionGroupName(iter().keyword());
936  const dictionary& regionDict = iter().dict();
937 
938  labelList regionIDs = findStrings(regionGroupName, allRegionNames);
939 
940  const wordList regionNames(allRegionNames, regionIDs);
941 
942  regionGroupNames_.append(compositeName(regionNames));
943  regionGroupRegions_.append(regionNames);
944 
945 
946  forAllConstIter(dictionary, regionDict, regionIter)
947  {
948  if (!regionIter().isDict())
949  {
950  FatalIOErrorInFunction(regionDict)
951  << "Regions must be specified in dictionary format"
952  << exit(FatalIOError);
953  }
954  const wordRe groupName(regionIter().keyword());
955  const dictionary& groupDict = regionIter().dict();
956 
957  label nGroups = groupNames_.size();
958  const wordList readFields(groupDict.lookup("readFields"));
959  const wordList writeFields(groupDict.lookup("writeFields"));
960 
961  HashTable<labelList>::iterator fnd = regionToGroups_.find
962  (
963  regionGroupNames_.last()
964  );
965  if (fnd != regionToGroups_.end())
966  {
967  fnd().append(nGroups);
968  }
969  else
970  {
971  regionToGroups_.insert
972  (
973  regionGroupNames_.last(),
974  labelList(1, nGroups)
975  );
976  }
977  groupNames_.append(groupName);
978  groupReadFields_.append(readFields);
979  groupWriteFields_.append(writeFields);
980  }
981  }
982 
983 
984  // Print a bit
985  if (log_)
986  {
987  Info<< type() << ": Communicating with regions:" << endl;
988  forAll(regionGroupNames_, rgI)
989  {
990  //const wordList& regionNames = regionGroupRegions_[rgI];
991  const word& compName = regionGroupNames_[rgI];
992 
993  Info<< "Region: " << compName << endl << incrIndent;
994  const labelList& groups = regionToGroups_[compName];
995  forAll(groups, i)
996  {
997  label groupI = groups[i];
998  const wordRe& groupName = groupNames_[groupI];
999 
1000  Info<< indent << "patchGroup: " << groupName << "\t"
1001  << endl
1002  << incrIndent
1003  << indent << "Reading fields: "
1004  << groupReadFields_[groupI]
1005  << endl
1006  << indent << "Writing fields: "
1007  << groupWriteFields_[groupI]
1008  << endl
1009  << decrIndent;
1010  }
1011  Info<< decrIndent;
1012  }
1013  Info<< endl;
1014  }
1015 
1016 
1017  // Note: we should not have to make directories since the geometry
1018  // should already be written - but just make sure
1019  if (Pstream::master())
1020  {
1021  forAll(regionGroupNames_, rgI)
1022  {
1023  const word& compName = regionGroupNames_[rgI];
1024 
1025  const labelList& groups = regionToGroups_[compName];
1026  forAll(groups, i)
1027  {
1028  label groupI = groups[i];
1029  const wordRe& groupName = groupNames_[groupI];
1030 
1031  fileName dir(groupDir(commsDir_, compName, groupName));
1032  if (!isDir(dir))
1033  {
1034  if (log_)
1035  {
1036  Info<< type() << ": creating communications directory "
1037  << dir << endl;
1038  }
1039  mkDir(dir);
1040  }
1041  }
1042  }
1043  }
1044 
1045  return true;
1046 }
1047 
1048 
1050 {}
1051 
1052 
1054 {}
1055 
1056 
1057 // ************************************************************************* //
volFields.H
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Foam::externalCoupledFunctionObject::writeData
void writeData() const
Write data for all regions, all fields.
Definition: externalCoupledFunctionObject.C:653
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::UOPstream
Output inter-processor communications stream operating on external buffer.
Definition: UOPstream.H:54
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::exists
bool exists(const fileName &, const bool checkGzip=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: POSIX.C:608
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:86
Foam::HashTable::iterator
An STL-conforming iterator.
Definition: HashTable.H:415
Foam::externalCoupledFunctionObject::createLockFile
void createLockFile() const
Create lock file.
Definition: externalCoupledFunctionObject.C:91
Foam::polyMesh::defaultRegion
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:306
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::externalCoupledFunctionObject::timeSet
virtual bool timeSet()
Called when time was set at the end of the Time::operator++.
Definition: externalCoupledFunctionObject.C:887
Foam::IFstream
Input from file stream.
Definition: IFstream.H:81
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:56
Foam::dictionary::readIfPresent
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Definition: dictionaryTemplates.C:94
Foam::externalCoupledFunctionObject::readLines
void readLines(const label nRows, autoPtr< IFstream > &masterFilePtr, OStringStream &data) const
Read (and distribute) lines from stream. Every processor.
Definition: externalCoupledFunctionObject.C:311
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::rm
bool rm(const fileName &)
Remove a file, returning true if successful otherwise false.
Definition: POSIX.C:954
Foam::externalCoupledFunctionObject::readColumns
void readColumns(const label nRows, const label nColumns, autoPtr< IFstream > &masterFilePtr, List< scalarField > &data) const
Read (and distribute) scalar columns from stream. Every processor.
Definition: externalCoupledFunctionObject.C:241
Foam::externalCoupledFunctionObject::baseDir
fileName baseDir() const
Return the file path to the base communications directory.
Definition: externalCoupledFunctionObject.C:57
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
globalIndex.H
Foam::UPstream::nProcs
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:387
Foam::externalCoupledFunctionObject::removeWriteFiles
void removeWriteFiles() const
Remove files written by OpenFOAM.
Definition: externalCoupledFunctionObject.C:159
Foam::externalCoupledFunctionObject::commsDir_
fileName commsDir_
Path to communications directory.
Definition: externalCoupledFunctionObject.H:156
Foam::PstreamBuffers
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Definition: PstreamBuffers.H:85
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::externalCoupledFunctionObject::lockName
static word lockName
Name of lock file.
Definition: externalCoupledFunctionObject.H:294
Foam::dictionary::lookupOrDefault
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Definition: dictionaryTemplates.C:33
Foam::globalIndex::localSize
label localSize() const
My local size.
Definition: globalIndexI.H:60
Foam::FatalIOError
IOerror FatalIOError
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::externalCoupledFunctionObject::execute
virtual bool execute(const bool forceWrite)
Called at each ++ or += of the time-loop.
Definition: externalCoupledFunctionObject.C:835
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:74
Foam::externalCoupledFunctionObject::start
virtual bool start()
Called at the start of the time-loop.
Definition: externalCoupledFunctionObject.C:829
Foam::readFields
This function object reads fields from the time directories and adds them to the mesh database for fu...
Definition: readFields.H:104
Foam::externalCoupledFunctionObject::read
virtual bool read(const dictionary &)
Read and set the function object if its data have changed.
Definition: externalCoupledFunctionObject.C:900
patchFaces
labelList patchFaces(const polyBoundaryMesh &patches, const wordList &names)
Definition: extrudeMesh.C:148
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
Foam::sleep
unsigned int sleep(const unsigned int)
Sleep for the specified number of seconds.
Definition: POSIX.C:1054
Foam::wordRe
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:74
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::functionObject
Abstract base-class for Time/database function objects.
Definition: functionObject.H:58
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
OFstream.H
Foam::globalMeshData::mergePoints
autoPtr< globalIndex > mergePoints(labelList &pointToGlobal, labelList &uniquePoints) const
Helper for merging (collocated!) mesh point data.
Definition: globalMeshData.C:2374
Foam::DynamicField
Dynamically sized Field.
Definition: DynamicField.H:49
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::inplaceRenumber
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
Definition: ListOpsTemplates.C:57
Foam::externalCoupledFunctionObject::removeReadFiles
void removeReadFiles() const
Remove files written by external code.
Definition: externalCoupledFunctionObject.C:126
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
Foam::sortedOrder
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
Definition: ListOpsTemplates.C:179
Foam::externalCoupledFunctionObject::wait
void wait() const
Wait for response from external source.
Definition: externalCoupledFunctionObject.C:192
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
Foam::UPstream::nonBlocking
@ nonBlocking
Definition: UPstream.H:68
Foam::label
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
Foam::externalCoupledFunctionObject::patchKey
static string patchKey
Name of patch key, e.g. '# Patch:' when looking for start of patch data.
Definition: externalCoupledFunctionObject.H:297
Foam::orOp
Definition: ops.H:178
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::externalCoupledFunctionObject::adjustTimeStep
virtual bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
Definition: externalCoupledFunctionObject.C:894
Foam::DynamicField::append
DynamicField< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::IndirectList
A List with indirect addressing.
Definition: IndirectList.H:102
Foam::UPtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:53
Foam::UPstream::masterNo
static int masterNo()
Process index of the master.
Definition: UPstream.H:393
IFstream.H
Foam::PstreamBuffers::finishedSends
void finishedSends(const bool block=true)
Mark all sends as having been done. This will start receives.
Definition: PstreamBuffers.C:82
Foam::externalCoupledFunctionObject::updateMesh
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
Definition: externalCoupledFunctionObject.C:1049
Foam::identity
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
dict
dictionary dict
Definition: searchingEngine.H:14
writeData
const bool writeData(readBool(pdfDictionary.lookup("writeData")))
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
fvMesh.H
Foam::IStringStream
Input from memory buffer stream.
Definition: IStringStream.H:49
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:235
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::externalCoupledFunctionObject::groupDir
static fileName groupDir(const fileName &commsDir, const word &regionsName, const wordRe &groupName)
Return the file path to the communications directory for the region.
Definition: externalCoupledFunctionObject.C:67
Foam::isDir
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:615
Foam::isFile
bool isFile(const fileName &, const bool checkGzip=true)
Does the name exist as a FILE in the file system?
Definition: POSIX.C:622
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
Foam::HashTable::sortedToc
List< Key > sortedToc() const
Return the table of contents as a sorted list.
Definition: HashTable.C:216
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:405
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:399
Foam::externalCoupledFunctionObject::writeGeometry
static void writeGeometry(const UPtrList< const fvMesh > &meshes, const fileName &commsDir, const wordRe &groupName)
Write geometry for the group/patch.
Definition: externalCoupledFunctionObject.C:373
Foam::externalCoupledFunctionObject::checkOrder
static void checkOrder(const wordList &)
Definition: externalCoupledFunctionObject.C:568
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::externalCoupledFunctionObject::externalCoupledFunctionObject
externalCoupledFunctionObject(const externalCoupledFunctionObject &)
Disallow default bitwise copy construc.
Foam::externalCoupledFunctionObject::~externalCoupledFunctionObject
virtual ~externalCoupledFunctionObject()
Destructor.
Definition: externalCoupledFunctionObject.C:811
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::findStrings
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1004
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::Pstream::gatherList
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
Definition: gatherScatterList.C:49
DynamicField.H
Foam::externalCoupledFunctionObject::movePoints
virtual void movePoints(const polyMesh &mesh)
Update for changes of mesh.
Definition: externalCoupledFunctionObject.C:1053
Foam::sumOp
Definition: ops.H:162
f
labelList f(nPoints)
Foam::globalIndex::size
label size() const
Global sum of localSizes.
Definition: globalIndexI.H:66
Foam::externalCoupledFunctionObject::lockFile
fileName lockFile() const
Return the file path to the lock file.
Definition: externalCoupledFunctionObject.C:85
Foam::fieldNames
wordList fieldNames(const IOobjectList &objects, const bool syncPar)
Get sorted names of fields of type. If syncPar and running in parallel.
Definition: ReadFields.C:36
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::OStringStream
Output to memory buffer stream.
Definition: OStringStream.H:49
Foam::UPtrList::set
bool set(const label) const
Is element set.
Foam::autoPtr::valid
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set).
Definition: autoPtrI.H:83
Foam::PtrList::size
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::line
A line primitive.
Definition: line.H:56
Foam::externalCoupledFunctionObject::compositeName
static word compositeName(const wordList &)
Create single name by appending words (in sorted order),.
Definition: externalCoupledFunctionObject.C:528
Foam::externalCoupledFunctionObject::end
virtual bool end()
Called when Time::run() determines that the time-loop exits.
Definition: externalCoupledFunctionObject.C:873
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Foam::autoPtr::reset
void reset(T *=0)
If object pointer already set, delete object and set to given.
Definition: autoPtrI.H:114
Foam::PrimitivePatch::localFaces
const List< Face > & localFaces() const
Return patch faces addressing into local point list.
Definition: PrimitivePatchTemplate.C:372
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:330
Foam::fileName::clean
bool clean()
Cleanup file name.
Definition: fileName.C:97
Foam::readBool
bool readBool(Istream &)
Definition: boolIO.C:60
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::UIPstream
Input inter-processor communications stream operating on external buffer.
Definition: UIPstream.H:53
Foam::externalCoupledFunctionObject::on
virtual void on()
Switch the function object on.
Definition: externalCoupledFunctionObject.C:817
Foam::polyMesh::globalData
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1143
Foam::PrimitivePatch::meshPointMap
const Map< label > & meshPointMap() const
Mesh point map. Given the global point index find its.
Definition: PrimitivePatchTemplate.C:412
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
Foam::polyBoundaryMesh::patchSet
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool usePatchGroups=true) const
Return the set of patch IDs corresponding to the given names.
Definition: polyBoundaryMesh.C:750
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::PrimitivePatch::meshPoints
const labelList & meshPoints() const
Return labelList of mesh points in patch.
Definition: PrimitivePatchTemplate.C:392
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
Foam::mkDir
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:419
Foam::externalCoupledFunctionObject::initialise
void initialise()
Definition: externalCoupledFunctionObject.C:723
Foam::externalCoupledFunctionObject::removeLockFile
void removeLockFile() const
Remove lock file.
Definition: externalCoupledFunctionObject.C:113
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
Foam::readFields
void readFields(const typename GeoMesh::Mesh &mesh, const IOobjectList &objects, PtrList< GeometricField< Type, PatchField, GeoMesh > > &fields, const bool readOldTime)
Definition: readFields.C:33
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::OSstream::flush
virtual void flush()
Flush stream.
Definition: OSstream.C:246
Foam::externalCoupledFunctionObject::readData
void readData()
Read data for all regions, all fields.
Definition: externalCoupledFunctionObject.C:583
externalCoupledFunctionObject.H
Foam::fvMesh::name
const word & name() const
Return reference to name.
Definition: fvMesh.H:257
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88
Foam::UPtrList::size
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:31
Foam::externalCoupledFunctionObject::off
virtual void off()
Switch the function object off.
Definition: externalCoupledFunctionObject.C:823