43 bool Foam::functionObjects::externalCoupled::readData
45 const UPtrList<const fvMesh>&
meshes,
46 const wordRe& groupName,
50 typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
51 typedef externalCoupledMixedFvPatchField<Type> patchFieldType;
61 autoPtr<IFstream> masterFilePtr;
64 const fileName transferFile
70 Log <<
type() <<
": reading data from " << transferFile <<
endl;
72 masterFilePtr.reset(
new IFstream(transferFile));
74 if (!masterFilePtr().good())
78 <<
", field " << fieldName
84 const wordRes patchSelection(
Foam::one{}, groupName);
90 auto* vfptr =
mesh.getObjectPtr<volFieldType>(fieldName);
98 auto& bf = vfptr->boundaryFieldRef();
103 mesh.boundaryMesh().patchSet(patchSelection).sortedToc()
109 if (isA<patchFieldType>(bf[patchi]))
114 patchFieldType& pf = refCast<patchFieldType>
128 ISpanStream isstr(lines);
135 pf.patchFieldType::evaluate();
137 else if (
isA<mixedFvPatchField<Type>>(bf[patchi]))
139 mixedFvPatchField<Type>& pf = refCast<mixedFvPatchField<Type>>
146 List<scalarField> data;
159 Field<Type>& refValue = pf.refValue();
167 refValue.replace(cmpt, data[columni++]);
169 Field<Type>& refGrad = pf.refGrad();
177 refGrad.replace(cmpt, data[columni++]);
179 pf.valueFraction() = data[columni];
183 pf.mixedFvPatchField<Type>::evaluate();
185 else if (
isA<fixedGradientFvPatchField<Type>>(bf[patchi]))
187 fixedGradientFvPatchField<Type>& pf =
188 refCast<fixedGradientFvPatchField<Type>>(bf[patchi]);
191 List<scalarField> data;
201 Field<Type>& gradient = pf.gradient();
218 pf.fixedGradientFvPatchField<Type>::evaluate();
220 else if (
isA<fixedValueFvPatchField<Type>>(bf[patchi]))
222 fixedValueFvPatchField<Type>& pf =
223 refCast<fixedValueFvPatchField<Type>>(bf[patchi]);
226 List<scalarField> data;
236 Field<Type> value(bf[patchi].size());
244 value.replace(cmpt, data[cmpt]);
251 pf.fixedValueFvPatchField<Type>::evaluate();
256 <<
"Unsupported boundary condition " << bf[patchi].type()
257 <<
" for patch " << bf[patchi].patch().name()
258 <<
" in region " <<
mesh.name()
262 initialisedCoupling_ =
true;
271 bool Foam::functionObjects::externalCoupled::writeData
273 const UPtrList<const fvMesh>&
meshes,
274 const wordRe& groupName,
275 const word& fieldName
278 typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
279 typedef externalCoupledMixedFvPatchField<Type> patchFieldType;
289 autoPtr<OFstream> masterFilePtr;
292 const fileName transferFile
294 groupDir(commDirectory(), compositeName(
regionNames), groupName)
298 Log <<
type() <<
": writing data to " << transferFile <<
endl;
300 masterFilePtr.reset(
new OFstream(transferFile));
302 if (!masterFilePtr().good())
305 <<
"Cannot open file for region " << compositeName(
regionNames)
306 <<
", field " << fieldName
312 const wordRes patchSelection(
Foam::one{}, groupName);
314 bool headerDone =
false;
319 const auto* vfptr =
mesh.getObjectPtr<volFieldType>(fieldName);
327 const auto& bf = vfptr->boundaryField();
332 mesh.boundaryMesh().patchSet(patchSelection).sortedToc()
340 if (isA<patchFieldType>(bf[patchi]))
345 const patchFieldType& pf = refCast<const patchFieldType>
361 pf.writeHeader(masterFilePtr());
364 masterFilePtr() <<
os.str().c_str();
371 masterFilePtr() << str.c_str();
379 else if (
isA<mixedFvPatchField<Type>>(bf[patchi]))
381 const mixedFvPatchField<Type>& pf =
382 refCast<const mixedFvPatchField<Type>>(bf[patchi]);
384 const globalIndex glob
386 globalIndex::gatherOnly{},
390 Field<Type> value(glob.gather(pf));
391 Field<Type>
snGrad(glob.gather(pf.snGrad()()));
392 Field<Type> refValue(glob.gather(pf.refValue()));
393 Field<Type> refGrad(glob.gather(pf.refGrad()));
394 scalarField valueFraction(glob.gather(pf.valueFraction()));
405 << valueFraction[facei] <<
nl;
413 const globalIndex glob
415 globalIndex::gatherOnly{},
419 Field<Type> value(glob.gather(bf[patchi]));
420 Field<Type>
snGrad(glob.gather(bf[patchi].snGrad()()));
const labelList patchIDs(pbm.indices(polyPatchNames, true))
Input/output streams with (internal or external) character storage.
errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Input/output from string buffers.
constexpr char nl
The newline '\n' character (0x0a)
Ostream & endl(Ostream &os)
Add newline and flush stream.
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
#define forAll(list, i)
Loop across all elements in list.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
static void recv(Type &value, const int fromProcNo, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Receive and deserialize a value. Uses operator>> for de-serialization.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
static constexpr int masterNo() noexcept
Relative rank for the master process - is always 0.
label size() const noexcept
The number of entries in the list.
virtual const word & type() const =0
Runtime type information.
Foam::PtrList< Foam::fvMesh > meshes(regionNames.size())
OBJstream os(runTime.globalPath()/outputName)
List< word > wordList
List of word.
static word compositeName(const wordList &)
Create single name by appending words (in sorted order), separated by '_'.
const fileName & commDirectory() const
Return the file path to the base communications directory.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
List< label > labelList
A List of labels.
bool send()
Send buffer contents now and not in destructor [advanced usage]. Returns true on success.
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...