36 Foam::word Foam::externalCoupledMixedFvPatchField<Type>::lockName =
"OpenFOAM";
40 Foam::externalCoupledMixedFvPatchField<Type>::patchKey =
"# Patch: ";
67 const volFieldType& cvf =
68 static_cast<const volFieldType&
>(this->internalField());
70 volFieldType& vf =
const_cast<volFieldType&
>(cvf);
72 typename volFieldType::Boundary& bf = vf.boundaryFieldRef();
75 label nPatch = bf.size();
76 reduce(nPatch, maxOp<label>());
78 offsets_.setSize(nPatch);
81 offsets_[i].setSize(Pstream::nProcs());
88 label patchi = patchIDs[i];
90 patchType& pf = refCast<patchType>(bf[
patchi]);
92 offsets_[
patchi][Pstream::myProcNo()] = pf.size();
105 int tag = Pstream::msgType() + 1;
108 Pstream::gatherList(offsets_[i], tag);
109 Pstream::scatterList(offsets_[i], tag);
112 label patchOffset = 0;
116 List<label>& procOffsets = offsets_[
patchi];
118 forAll(procOffsets, proci)
120 label o = procOffsets[proci];
123 procOffsets[proci] = patchOffset + sumOffset;
127 patchOffset += sumOffset;
139 int tag = Pstream::msgType() + 1;
141 const label proci = Pstream::myProcNo();
142 const polyPatch& p = this->patch().
patch();
143 const polyMesh& mesh = p.boundaryMesh().mesh();
147 (void)mesh.globalData().mergePoints
155 List<pointField>
allPoints(Pstream::nProcs());
159 List<faceList> allFaces(Pstream::nProcs());
160 faceList& patchFaces = allFaces[proci];
161 patchFaces = p.localFaces();
167 Pstream::gatherList(allFaces, tag);
169 if (Pstream::master())
173 ListListOps::combine<pointField>(
allPoints, accessOp<pointField>())
177 osPoints << patchKey.c_str() << this->patch().name() << pts <<
endl;
181 ListListOps::combine<faceList>(allFaces, accessOp<faceList>())
185 osFaces<< patchKey.c_str() << this->patch().name() << fcs <<
endl;
193 return fileName(baseDir()/(lockName +
".lock"));
200 if (!master_ || !Pstream::master())
205 const fileName fName(lockFile());
226 if (!master_ || !Pstream::master())
245 const volFieldType& cvf =
246 static_cast<const volFieldType&
>(this->internalField());
248 const typename volFieldType::Boundary& bf =
251 forAll(coupledPatchIDs_, i)
253 label patchi = coupledPatchIDs_[i];
255 const patchType& pf = refCast<const patchType>(bf[
patchi]);
269 const fileName fName(lockFile());
275 Info<<
type() <<
": beginning wait for lock file " << fName <<
endl;
280 if (Pstream::master())
282 if (totalTime > timeOut_)
285 <<
"Wait time exceeded time out time of " << timeOut_
302 sleep(waitInterval_);
303 totalTime += waitInterval_;
313 reduce(found, sumOp<label>());
327 <<
"Unable to open data transfer file " << is.name()
328 <<
" for patch " << this->patch().name()
332 label offset = offsets_[this->patch().index()][Pstream::myProcNo()];
336 for (
label i = 0; i < offset; i++)
345 <<
"Unable to scan forward to appropriate read position for " 346 <<
"data transfer file " << is.name()
347 <<
" for patch " << this->patch().name()
369 forAll(this->patch(), facei)
373 is >> this->refValue()[facei]
374 >> this->refGrad()[facei]
375 >> this->valueFraction()[facei];
380 <<
"Insufficient data for patch " 381 << this->patch().name()
382 <<
" in file " << is.
name()
410 static_cast<const volFieldType&
>(this->internalField());
415 forAll(coupledPatchIDs_, i)
417 label patchi = coupledPatchIDs_[i];
432 os <<
"# Values: magSf value snGrad" <<
endl;
447 commsDir_(
"unknown-commsDir"),
448 fName_(
"unknown-fName"),
452 initByExternal_(
false),
459 this->refValue() =
Zero;
460 this->refGrad() =
Zero;
461 this->valueFraction() = 0.0;
475 commsDir_(dict.
lookup(
"commsDir")),
476 fName_(dict.
lookup(
"file")),
487 if (dict.
found(
"value"))
501 if (Pstream::master())
506 if (!initByExternal_)
512 this->refValue() = *
this;
513 this->refGrad() =
Zero;
514 this->valueFraction() = 1.0;
529 commsDir_(ptf.commsDir_),
531 waitInterval_(ptf.waitInterval_),
532 timeOut_(ptf.timeOut_),
533 calcFrequency_(ptf.calcFrequency_),
534 initByExternal_(ptf.initByExternal_),
536 master_(ptf.master_),
537 offsets_(ptf.offsets_),
538 initialised_(ptf.initialised_),
539 coupledPatchIDs_(ptf.coupledPatchIDs_)
552 commsDir_(ecmpf.commsDir_),
553 fName_(ecmpf.fName_),
554 waitInterval_(ecmpf.waitInterval_),
555 timeOut_(ecmpf.timeOut_),
556 calcFrequency_(ecmpf.calcFrequency_),
557 initByExternal_(ecmpf.initByExternal_),
559 master_(ecmpf.master_),
560 offsets_(ecmpf.offsets_),
561 initialised_(ecmpf.initialised_),
562 coupledPatchIDs_(ecmpf.coupledPatchIDs_)
590 static_cast<const volFieldType&
>(this->internalField());
601 if (isA<patchType>(bf[patchi]))
603 coupledPatchIDs.append(patchi);
607 coupledPatchIDs_.transfer(coupledPatchIDs);
616 forAll(coupledPatchIDs_, i)
618 label patchi = coupledPatchIDs_[i];
622 pf.setMaster(coupledPatchIDs_);
632 forAll(coupledPatchIDs_, i)
634 label patchi = coupledPatchIDs_[i];
644 setMaster(coupledPatchIDs_);
657 if (!initialised_ || this->db().time().
timeIndex() % calcFrequency_ == 0)
659 const fileName transferFile(baseDir()/fName_);
662 initialise(transferFile);
673 if (master_ && Pstream::master())
676 rm(transferFile +
".out");
680 readData(transferFile);
699 if (Pstream::parRun())
701 int tag = Pstream::msgType() + 1;
704 magSfs[Pstream::myProcNo()].
setSize(this->patch().size());
705 magSfs[Pstream::myProcNo()] = this->patch().magSf();
706 Pstream::gatherList(magSfs, tag);
709 values[Pstream::myProcNo()].
setSize(this->patch().size());
710 values[Pstream::myProcNo()] = this->refValue();
711 Pstream::gatherList(values, tag);
714 snGrads[Pstream::myProcNo()].
setSize(this->patch().size());
715 snGrads[Pstream::myProcNo()] = this->
snGrad();
716 Pstream::gatherList(snGrads, tag);
718 if (Pstream::master())
728 os << magSf[facei] << token::SPACE
729 << value[facei] << token::SPACE
730 << snGrad[facei] <<
nl;
745 os << magSf[facei] << token::SPACE
746 << value[facei] << token::SPACE
747 << snGrad[facei] <<
nl;
759 static_cast<const volFieldType&
>(this->internalField());
764 OFstream osPoints(baseDir()/
"patchPoints");
765 OFstream osFaces(baseDir()/
"patchFaces");
769 Info<<
"writing collated patch points to: " << osPoints.
name() <<
nl 770 <<
"writing collated patch faces to: " << osFaces.
name() <<
endl;
775 if (isA<patchType>(bf[patchi]))
779 pf.writeGeometry(osPoints, osFaces);
792 writeEntry(os,
"waitInterval", waitInterval_);
794 writeEntry(os,
"calcFrequency", calcFrequency_);
795 writeEntry(os,
"initByExternal", initByExternal_);
This boundary condition provides an interface to an external application. Values are transferred as p...
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
#define forAll(list, i)
Loop across all elements in list.
virtual void transferData(OFstream &os) const
Transfer data for external source.
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
A class for handling file names.
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
void writeGeometry() const
Write the geometry to the comms dir.
errorManipArg< error, int > exit(error &err, const int errNo=1)
void evaluate(GeometricField< Type, PatchField, GeoMesh > &result, const Function1< Type > &func, const GeometricField< Type, PatchField, GeoMesh > &x)
A list of keyword definitions, which are a keyword followed by any number of values (e...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
commsTypes
Types of communications.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void size(const label)
Override size to be inconsistent with allocated storage.
virtual ~externalCoupledMixedFvPatchField()
Destructor.
Ostream & endl(Ostream &os)
Add newline and flush stream.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
This boundary condition provides a base class for 'mixed' type boundary conditions, i.e. conditions that mix fixed value and patch-normal gradient conditions.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
const fileName & name() const
Return the name of the stream.
bool good() const
Return true if next operation might succeed.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
vectorField pointField
pointField is a vectorField.
virtual void writeHeader(OFstream &os) const
Write header to transfer file.
void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Write header.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Pre-declare SubField and related Field type.
A class for handling words, derived from string.
Foam::fvPatchFieldMapper.
const fileName & name() const
Return the name of the stream.
virtual void flush()
Flush stream.
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
List< label > labelList
A List of labels.
errorManip< error > abort(error &err)
const fvPatch & patch() const
Return patch.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
const bool writeData(readBool(pdfDictionary.lookup("writeData")))
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
word name(const complex &)
Return a string representation of a complex.
virtual void readData(const fileName &transferFile)
Read data from external source.
label size() const
Return the number of elements in the UPtrList.
virtual void writeData(const fileName &transferFile) const
Write data for external source - calls transferData.
void setSize(const label)
Reset size of List.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
externalCoupledMixedFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
bool rm(const fileName &)
Remove a file, returning true if successful otherwise false.
A class for handling character strings derived from std::string.
unsigned int sleep(const unsigned int)
Sleep for the specified number of seconds.
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
virtual void write(Ostream &) const
Write.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.