35 Foam::word Foam::externalCoupledMixedFvPatchField<Type>::lockName =
"OpenFOAM";
39 Foam::externalCoupledMixedFvPatchField<Type>::patchKey =
"# Patch: ";
66 const volFieldType& cvf =
67 static_cast<const volFieldType&
>(this->internalField());
69 volFieldType& vf =
const_cast<volFieldType&
>(cvf);
71 typename volFieldType::Boundary& bf = vf.boundaryFieldRef();
74 label nPatch = bf.size();
75 reduce(nPatch, maxOp<label>());
77 offsets_.setSize(nPatch);
80 offsets_[i].setSize(Pstream::nProcs());
87 label patchi = patchIDs[i];
89 patchType& pf = refCast<patchType>(bf[
patchi]);
91 offsets_[
patchi][Pstream::myProcNo()] = pf.size();
104 int tag = Pstream::msgType() + 1;
107 Pstream::gatherList(offsets_[i], tag);
108 Pstream::scatterList(offsets_[i], tag);
111 label patchOffset = 0;
115 List<label>& procOffsets = offsets_[
patchi];
117 forAll(procOffsets, proci)
119 label o = procOffsets[proci];
122 procOffsets[proci] = patchOffset + sumOffset;
126 patchOffset += sumOffset;
138 int tag = Pstream::msgType() + 1;
140 const label proci = Pstream::myProcNo();
141 const polyPatch& p = this->patch().
patch();
142 const polyMesh& mesh = p.boundaryMesh().mesh();
146 (void)mesh.globalData().mergePoints
154 List<pointField>
allPoints(Pstream::nProcs());
158 List<faceList> allFaces(Pstream::nProcs());
159 faceList& patchFaces = allFaces[proci];
160 patchFaces = p.localFaces();
166 Pstream::gatherList(allFaces, tag);
168 if (Pstream::master())
172 ListListOps::combine<pointField>(
allPoints, accessOp<pointField>())
176 osPoints << patchKey.c_str() << this->patch().name() << pts <<
endl;
180 ListListOps::combine<faceList>(allFaces, accessOp<faceList>())
184 osFaces<< patchKey.c_str() << this->patch().name() << fcs <<
endl;
192 return fileName(baseDir()/(lockName +
".lock"));
199 if (!master_ || !Pstream::master())
204 const fileName fName(lockFile());
225 if (!master_ || !Pstream::master())
244 const volFieldType& cvf =
245 static_cast<const volFieldType&
>(this->internalField());
247 const typename volFieldType::Boundary& bf =
250 forAll(coupledPatchIDs_, i)
252 label patchi = coupledPatchIDs_[i];
254 const patchType& pf = refCast<const patchType>(bf[
patchi]);
268 const fileName fName(lockFile());
274 Info<<
type() <<
": beginning wait for lock file " << fName <<
endl;
279 if (Pstream::master())
281 if (totalTime > timeOut_)
284 <<
"Wait time exceeded time out time of " << timeOut_
301 sleep(waitInterval_);
302 totalTime += waitInterval_;
312 reduce(found, sumOp<label>());
326 <<
"Unable to open data transfer file " << is.name()
327 <<
" for patch " << this->patch().name()
331 label offset = offsets_[this->patch().index()][Pstream::myProcNo()];
335 for (
label i = 0; i < offset; i++)
344 <<
"Unable to scan forward to appropriate read position for " 345 <<
"data transfer file " << is.name()
346 <<
" for patch " << this->patch().name()
368 forAll(this->patch(), facei)
372 is >> this->refValue()[facei]
373 >> this->refGrad()[facei]
374 >> this->valueFraction()[facei];
379 <<
"Insufficient data for patch " 380 << this->patch().name()
381 <<
" in file " << is.
name()
409 static_cast<const volFieldType&
>(this->internalField());
411 const typename volFieldType::Boundary& bf =
414 forAll(coupledPatchIDs_, i)
416 label patchi = coupledPatchIDs_[i];
431 os <<
"# Values: magSf value snGrad" <<
endl;
446 commsDir_(
"unknown-commsDir"),
447 fName_(
"unknown-fName"),
451 initByExternal_(
false),
458 this->refValue() =
Zero;
459 this->refGrad() =
Zero;
460 this->valueFraction() = 0.0;
475 commsDir_(ptf.commsDir_),
477 waitInterval_(ptf.waitInterval_),
478 timeOut_(ptf.timeOut_),
479 calcFrequency_(ptf.calcFrequency_),
480 initByExternal_(ptf.initByExternal_),
482 master_(ptf.master_),
483 offsets_(ptf.offsets_),
484 initialised_(ptf.initialised_),
485 coupledPatchIDs_(ptf.coupledPatchIDs_)
499 commsDir_(dict.
lookup(
"commsDir")),
500 fName_(dict.
lookup(
"file")),
511 if (dict.
found(
"value"))
525 if (Pstream::master())
530 if (!initByExternal_)
536 this->refValue() = *
this;
537 this->refGrad() =
Zero;
538 this->valueFraction() = 1.0;
550 commsDir_(ecmpf.commsDir_),
551 fName_(ecmpf.fName_),
552 waitInterval_(ecmpf.waitInterval_),
553 timeOut_(ecmpf.timeOut_),
554 calcFrequency_(ecmpf.calcFrequency_),
555 initByExternal_(ecmpf.initByExternal_),
557 master_(ecmpf.master_),
558 offsets_(ecmpf.offsets_),
559 initialised_(ecmpf.initialised_),
560 coupledPatchIDs_(ecmpf.coupledPatchIDs_)
573 commsDir_(ecmpf.commsDir_),
574 fName_(ecmpf.fName_),
575 waitInterval_(ecmpf.waitInterval_),
576 timeOut_(ecmpf.timeOut_),
577 calcFrequency_(ecmpf.calcFrequency_),
578 initByExternal_(ecmpf.initByExternal_),
580 master_(ecmpf.master_),
581 offsets_(ecmpf.offsets_),
582 initialised_(ecmpf.initialised_),
583 coupledPatchIDs_(ecmpf.coupledPatchIDs_)
611 static_cast<const volFieldType&
>(this->internalField());
622 if (isA<patchType>(bf[patchi]))
624 coupledPatchIDs.append(patchi);
628 coupledPatchIDs_.transfer(coupledPatchIDs);
637 forAll(coupledPatchIDs_, i)
639 label patchi = coupledPatchIDs_[i];
643 pf.setMaster(coupledPatchIDs_);
653 forAll(coupledPatchIDs_, i)
655 label patchi = coupledPatchIDs_[i];
665 setMaster(coupledPatchIDs_);
678 if (!initialised_ || this->db().time().
timeIndex() % calcFrequency_ == 0)
680 const fileName transferFile(baseDir()/fName_);
683 initialise(transferFile);
694 if (master_ && Pstream::master())
697 rm(transferFile +
".out");
701 readData(transferFile);
720 if (Pstream::parRun())
722 int tag = Pstream::msgType() + 1;
725 magSfs[Pstream::myProcNo()].
setSize(this->patch().size());
726 magSfs[Pstream::myProcNo()] = this->patch().magSf();
727 Pstream::gatherList(magSfs, tag);
730 values[Pstream::myProcNo()].
setSize(this->patch().size());
731 values[Pstream::myProcNo()] = this->refValue();
732 Pstream::gatherList(values, tag);
735 snGrads[Pstream::myProcNo()].
setSize(this->patch().size());
736 snGrads[Pstream::myProcNo()] = this->
snGrad();
737 Pstream::gatherList(snGrads, tag);
739 if (Pstream::master())
749 os << magSf[facei] << token::SPACE
750 << value[facei] << token::SPACE
751 << snGrad[facei] <<
nl;
766 os << magSf[facei] << token::SPACE
767 << value[facei] << token::SPACE
768 << snGrad[facei] <<
nl;
780 static_cast<const volFieldType&
>(this->internalField());
782 const typename volFieldType::Boundary& bf =
785 OFstream osPoints(baseDir()/
"patchPoints");
786 OFstream osFaces(baseDir()/
"patchFaces");
790 Info<<
"writing collated patch points to: " << osPoints.
name() <<
nl 791 <<
"writing collated patch faces to: " << osFaces.
name() <<
endl;
796 if (isA<patchType>(bf[patchi]))
800 pf.writeGeometry(osPoints, osFaces);
811 os.
writeKeyword(
"commsDir") << commsDir_ << token::END_STATEMENT <<
nl;
813 os.
writeKeyword(
"waitInterval") << waitInterval_ << token::END_STATEMENT
815 os.
writeKeyword(
"timeOut") << timeOut_ << token::END_STATEMENT <<
nl;
816 os.
writeKeyword(
"calcFrequency") << calcFrequency_ << token::END_STATEMENT
818 os.
writeKeyword(
"initByExternal") << initByExternal_ << token::END_STATEMENT
822 this->writeEntry(
"value", os);
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.
intWM_LABEL_SIZE_t 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)
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.
vectorField pointField
pointField is a vectorField.
virtual void writeHeader(OFstream &os) const
Write header to transfer file.
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.
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")))
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
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.
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.
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.