43bool 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()
128 ISpanStream isstr(lines);
135 pf.patchFieldType::evaluate();
137 else if (
isA<mixedFvPatchField<Type>>(bf[patchi]))
146 List<scalarField> data;
150 4*pTraits<Type>::nComponents+1,
157 direction columni = 2*pTraits<Type>::nComponents;
159 Field<Type>& refValue = pf.refValue();
163 cmpt < pTraits<Type>::nComponents;
167 refValue.replace(cmpt, data[columni++]);
169 Field<Type>& refGrad = pf.refGrad();
173 cmpt < pTraits<Type>::nComponents;
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 =
191 List<scalarField> data;
195 2*pTraits<Type>::nComponents,
201 Field<Type>& gradient = pf.gradient();
205 cmpt < pTraits<Type>::nComponents;
212 data[pTraits<Type>::nComponents+cmpt]
218 pf.fixedGradientFvPatchField<Type>::evaluate();
220 else if (
isA<fixedValueFvPatchField<Type>>(bf[patchi]))
222 fixedValueFvPatchField<Type>& pf =
226 List<scalarField> data;
230 pTraits<Type>::nComponents,
236 Field<Type> value(bf[patchi].size());
240 cmpt < pTraits<Type>::nComponents;
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;
271bool 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()
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 =
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()()));
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Input/output streams with (internal or external) character storage.
Input/output from string buffers.
static void recv(Type &value, const int fromProcNo, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Receive and deserialize a value. Uses operator>> for de-serialization.
bool send()
Send buffer contents now and not in destructor [advanced usage]. Returns true on success.
static constexpr int masterNo() noexcept
Relative rank for the master process - is always 0.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
label size() const noexcept
The number of entries in the list.
const fileName & commDirectory() const
Return the file path to the base communications directory.
virtual const word & type() const =0
Runtime type information.
static word compositeName(const wordList &)
Create single name by appending words (in sorted order), separated by '_'.
Foam::PtrList< Foam::fvMesh > meshes(regionNames.size())
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
List< word > wordList
List of word.
List< label > labelList
A List of labels.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.