42bool Foam::functionObjects::externalCoupled::readData
44 const UPtrList<const fvMesh>&
meshes,
45 const wordRe& groupName,
49 typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
50 typedef externalCoupledMixedFvPatchField<Type> patchFieldType;
60 autoPtr<IFstream> masterFilePtr;
63 const fileName transferFile
69 Log <<
type() <<
": reading data from " << transferFile <<
endl;
71 masterFilePtr.reset(
new IFstream(transferFile));
73 if (!masterFilePtr().good())
77 <<
", field " << fieldName
83 const wordRes patchSelection(one{}, groupName);
89 const volFieldType* vfptr =
mesh.
findObject<volFieldType>(fieldName);
97 typename volFieldType::Boundary& bf =
98 const_cast<volFieldType*
>(vfptr)->boundaryFieldRef();
107 for (
const label patchi : patchIDs)
109 if (isA<patchFieldType>(bf[patchi]))
114 patchFieldType& pf = refCast<patchFieldType>
129 pf.readData(IStringStream(
os.str())());
133 pf.patchFieldType::evaluate();
135 else if (
isA<mixedFvPatchField<Type>>(bf[patchi]))
137 mixedFvPatchField<Type>& pf = refCast<mixedFvPatchField<Type>>
144 List<scalarField> data;
148 4*pTraits<Type>::nComponents+1,
155 direction columni = 2*pTraits<Type>::nComponents;
157 Field<Type>& refValue = pf.refValue();
161 cmpt < pTraits<Type>::nComponents;
165 refValue.replace(cmpt, data[columni++]);
167 Field<Type>& refGrad = pf.refGrad();
171 cmpt < pTraits<Type>::nComponents;
175 refGrad.replace(cmpt, data[columni++]);
177 pf.valueFraction() = data[columni];
181 pf.mixedFvPatchField<Type>::evaluate();
183 else if (
isA<fixedGradientFvPatchField<Type>>(bf[patchi]))
185 fixedGradientFvPatchField<Type>& pf =
186 refCast<fixedGradientFvPatchField<Type>>(bf[patchi]);
189 List<scalarField> data;
193 2*pTraits<Type>::nComponents,
199 Field<Type>& gradient = pf.gradient();
203 cmpt < pTraits<Type>::nComponents;
210 data[pTraits<Type>::nComponents+cmpt]
216 pf.fixedGradientFvPatchField<Type>::evaluate();
218 else if (
isA<fixedValueFvPatchField<Type>>(bf[patchi]))
220 fixedValueFvPatchField<Type>& pf =
221 refCast<fixedValueFvPatchField<Type>>(bf[patchi]);
224 List<scalarField> data;
228 pTraits<Type>::nComponents,
234 Field<Type> value(bf[patchi].size());
238 cmpt < pTraits<Type>::nComponents;
242 value.replace(cmpt, data[cmpt]);
249 pf.fixedValueFvPatchField<Type>::evaluate();
254 <<
"Unsupported boundary condition " << bf[patchi].type()
255 <<
" for patch " << bf[patchi].patch().name()
260 initialisedCoupling_ =
true;
270Foam::functionObjects::externalCoupled::gatherAndCombine
282 auto& result = tresult.ref();
287 label globalElemi = 0;
289 forAll(gatheredValues, lsti)
291 globalElemi += gatheredValues[lsti].
size();
294 result.setSize(globalElemi);
298 forAll(gatheredValues, lsti)
304 result[globalElemi++] = sub[elemi];
314bool Foam::functionObjects::externalCoupled::writeData
318 const word& fieldName
337 groupDir(commDirectory(), compositeName(
regionNames), groupName)
341 Log <<
type() <<
": writing data to " << transferFile <<
endl;
345 if (!masterFilePtr().good())
348 <<
"Cannot open file for region " << compositeName(
regionNames)
349 <<
", field " << fieldName
355 const wordRes patchSelection(one{}, groupName);
357 bool headerDone =
false;
362 const volFieldType* vfptr =
mesh.findObject<volFieldType>(fieldName);
370 const typename volFieldType::Boundary& bf =
371 vfptr->boundaryField();
376 mesh.boundaryMesh().patchSet(patchSelection).sortedToc()
380 for (
const label patchi : patchIDs)
382 const globalIndex globalFaces(bf[patchi].size());
384 if (isA<patchFieldType>(bf[patchi]))
389 const patchFieldType& pf = refCast<const patchFieldType>
405 pf.writeHeader(masterFilePtr());
408 masterFilePtr() <<
os.str().c_str();
418 string str(fromSlave);
419 masterFilePtr() << str.c_str();
430 toMaster <<
os.str();
433 else if (
isA<mixedFvPatchField<Type>>(bf[patchi]))
435 const mixedFvPatchField<Type>& pf =
436 refCast<const mixedFvPatchField<Type>>(bf[patchi]);
438 Field<Type> value(gatherAndCombine(pf));
439 Field<Type>
snGrad(gatherAndCombine(pf.snGrad()()));
440 Field<Type> refValue(gatherAndCombine(pf.refValue()));
441 Field<Type> refGrad(gatherAndCombine(pf.refGrad()));
442 scalarField valueFraction(gatherAndCombine(pf.valueFraction()));
453 << valueFraction[facei] <<
nl;
460 Field<Type> value(gatherAndCombine(bf[patchi]));
461 Field<Type>
snGrad(gatherAndCombine(bf[patchi].
snGrad()()));
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Input/output from string buffers.
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Generic templated field type.
Generic GeometricField class.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Output to file stream, using an OSstream.
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
UPstream::rangeType subProcs() const noexcept
Range of sub-processes indices associated with PstreamBuffers.
static void gatherList(const List< commsStruct > &comms, List< T > &values, const int tag, const label comm)
void size(const label n)
Older name for setAddressableSize.
static constexpr int masterNo() noexcept
Process index of the master (always 0)
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
label size() const noexcept
The number of elements in the list.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
void reset(autoPtr< T > &&other) noexcept
Delete managed object and set to new given pointer.
Extends the mixed boundary condition with serialisation functions.
const fileName & commDirectory() const
Return the file path to the base communications directory.
A class for handling file names.
virtual const word & type() const =0
Runtime type information.
static word compositeName(const wordList &)
const word & name() const
Return reference to name.
const Type * findObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
int myProcNo() const noexcept
Return processor number.
splitCell * master() const
A class for managing temporary objects.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
A class for handling words, derived from Foam::string.
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)
List< word > wordList
A List of words.
List< label > labelList
A List of labels.
const TargetType * isA(const Type &t)
Check if dynamic_cast to TargetType is possible.
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.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
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.