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();
298 forAll(gatheredValues, lsti)
304 result[globalElemi++] = sub[elemi];
314 bool 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()()));