42 bool 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();
103 mesh.boundaryMesh().patchSet(patchSelection).sortedToc()
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()
256 <<
" in region " <<
mesh.name()
260 initialisedCoupling_ =
true;
270 Foam::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];
314 bool Foam::functionObjects::externalCoupled::writeData
316 const UPtrList<const fvMesh>&
meshes,
317 const wordRe& groupName,
318 const word& fieldName
321 typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
322 typedef externalCoupledMixedFvPatchField<Type> patchFieldType;
332 autoPtr<OFstream> masterFilePtr;
335 const fileName transferFile
337 groupDir(commDirectory(), compositeName(
regionNames), groupName)
341 Log <<
type() <<
": writing data to " << transferFile <<
endl;
343 masterFilePtr.reset(
new OFstream(transferFile));
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()()));
void size(const label n)
Older name for setAddressableSize.
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.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
constexpr char nl
The newline '\n' character (0x0a)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
#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 label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator) is 1 for serial run.
static void gatherList(const List< commsStruct > &comms, List< T > &values, const int tag, const label comm)
Gather data, but keep individual values separate. Uses the specified communication schedule...
"scheduled" : (MPI_Send, MPI_Recv)
Generic templated field type.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
static constexpr int masterNo() noexcept
Process index of the master (always 0)
label size() const noexcept
The number of elements in the list.
virtual const word & type() const =0
Runtime type information.
Foam::PtrList< Foam::fvMesh > meshes(regionNames.size())
OBJstream os(runTime.globalPath()/outputName)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
List< word > wordList
A List of words.
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)
Am I the master rank.
const Type * isA(const U &obj)
Check if dynamic_cast to Type is possible.
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
List< label > labelList
A List of labels.
A class for managing temporary objects.
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...