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;
55 regionNames[i] =
meshes[i].dbDir();
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())
76 <<
"Cannot open file for region " <<
compositeName(regionNames)
77 <<
", field " << fieldName
86 const volFieldType* vfptr =
mesh.findObject<volFieldType>(fieldName);
94 typename volFieldType::Boundary& bf =
95 const_cast<volFieldType*
>(vfptr)->boundaryFieldRef();
100 mesh.boundaryMesh().patchSet
102 List<wordRe>{groupName}
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
327 regionNames[i] =
meshes[i].dbDir();
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 bool headerDone =
false;
361 const volFieldType* vfptr =
mesh.findObject<volFieldType>(fieldName);
369 const typename volFieldType::Boundary& bf =
370 vfptr->boundaryField();
375 mesh.boundaryMesh().patchSet
377 List<wordRe>{groupName}
382 for (
const label patchi : patchIDs)
384 const globalIndex globalFaces(bf[patchi].size());
386 if (isA<patchFieldType>(bf[patchi]))
391 const patchFieldType& pf = refCast<const patchFieldType>
407 pf.writeHeader(masterFilePtr());
410 masterFilePtr() << os.str().c_str();
420 string str(fromSlave);
421 masterFilePtr() << str.c_str();
432 toMaster << os.str();
435 else if (
isA<mixedFvPatchField<Type>>(bf[patchi]))
437 const mixedFvPatchField<Type>& pf =
438 refCast<const mixedFvPatchField<Type>>(bf[patchi]);
440 Field<Type> value(gatherAndCombine(pf));
441 Field<Type>
snGrad(gatherAndCombine(pf.snGrad()()));
442 Field<Type> refValue(gatherAndCombine(pf.refValue()));
443 Field<Type> refGrad(gatherAndCombine(pf.refGrad()));
444 scalarField valueFraction(gatherAndCombine(pf.valueFraction()));
455 << valueFraction[facei] <<
nl;
462 Field<Type> value(gatherAndCombine(bf[patchi]));
463 Field<Type>
snGrad(gatherAndCombine(bf[patchi].
snGrad()()));