43 bool 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;
56 regionNames[i] =
meshes[i].dbDir();
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())
77 <<
"Cannot open file for region " <<
compositeName(regionNames)
78 <<
", field " << fieldName
87 const volFieldType* vfptr =
mesh.findObject<volFieldType>(fieldName);
95 typename volFieldType::Boundary& bf =
96 const_cast<volFieldType*
>(vfptr)->boundaryFieldRef();
101 mesh.boundaryMesh().patchSet
103 List<wordRe>{groupName}
108 for (
const label patchi : patchIDs)
110 if (isA<patchFieldType>(bf[patchi]))
115 patchFieldType& pf = refCast<patchFieldType>
130 pf.readData(IStringStream(os.str())());
134 pf.patchFieldType::evaluate();
136 else if (
isA<mixedFvPatchField<Type>>(bf[patchi]))
138 mixedFvPatchField<Type>& pf = refCast<mixedFvPatchField<Type>>
145 List<scalarField> data;
149 4*pTraits<Type>::nComponents+1,
156 direction columni = 2*pTraits<Type>::nComponents;
158 Field<Type>& refValue = pf.refValue();
162 cmpt < pTraits<Type>::nComponents;
166 refValue.replace(cmpt, data[columni++]);
168 Field<Type>& refGrad = pf.refGrad();
172 cmpt < pTraits<Type>::nComponents;
176 refGrad.replace(cmpt, data[columni++]);
178 pf.valueFraction() = data[columni];
182 pf.mixedFvPatchField<Type>::evaluate();
184 else if (
isA<fixedGradientFvPatchField<Type>>(bf[patchi]))
186 fixedGradientFvPatchField<Type>& pf =
187 refCast<fixedGradientFvPatchField<Type>>(bf[patchi]);
190 List<scalarField> data;
194 2*pTraits<Type>::nComponents,
200 Field<Type>& gradient = pf.gradient();
204 cmpt < pTraits<Type>::nComponents;
211 data[pTraits<Type>::nComponents+cmpt]
217 pf.fixedGradientFvPatchField<Type>::evaluate();
219 else if (
isA<fixedValueFvPatchField<Type>>(bf[patchi]))
221 fixedValueFvPatchField<Type>& pf =
222 refCast<fixedValueFvPatchField<Type>>(bf[patchi]);
225 List<scalarField> data;
229 pTraits<Type>::nComponents,
235 Field<Type> value(bf[patchi].size());
239 cmpt < pTraits<Type>::nComponents;
243 value.replace(cmpt, data[cmpt]);
250 pf.fixedValueFvPatchField<Type>::evaluate();
255 <<
"Unsupported boundary condition " << bf[patchi].type()
256 <<
" for patch " << bf[patchi].patch().name()
257 <<
" in region " <<
mesh.name()
261 initialisedCoupling_ =
true;
271 Foam::functionObjects::externalCoupled::gatherAndCombine
283 auto& result = tresult.ref();
288 label globalElemi = 0;
290 forAll(gatheredValues, lsti)
292 globalElemi += gatheredValues[lsti].size();
299 forAll(gatheredValues, lsti)
305 result[globalElemi++] = sub[elemi];
315 bool Foam::functionObjects::externalCoupled::writeData
319 const word& fieldName
328 regionNames[i] =
meshes[i].dbDir();
338 groupDir(commDirectory(), compositeName(regionNames), groupName)
342 Log <<
type() <<
": writing data to " << transferFile <<
endl;
346 if (!masterFilePtr().good())
349 <<
"Cannot open file for region " << compositeName(regionNames)
350 <<
", field " << fieldName
356 bool headerDone =
false;
362 const volFieldType* vfptr =
mesh.findObject<volFieldType>(fieldName);
370 const typename volFieldType::Boundary& bf =
371 vfptr->boundaryField();
376 mesh.boundaryMesh().patchSet
378 List<wordRe>{groupName}
383 for (
const label patchi : patchIDs)
385 const globalIndex globalFaces(bf[patchi].size());
387 if (isA<patchFieldType>(bf[patchi]))
392 const patchFieldType& pf = refCast<const patchFieldType>
408 pf.writeHeader(masterFilePtr());
411 masterFilePtr() << os.str().c_str();
421 string str(fromSlave);
422 masterFilePtr() << str.c_str();
433 toMaster << os.str();
436 else if (
isA<mixedFvPatchField<Type>>(bf[patchi]))
438 const mixedFvPatchField<Type>& pf =
439 refCast<const mixedFvPatchField<Type>>(bf[patchi]);
441 Field<Type> value(gatherAndCombine(pf));
442 Field<Type>
snGrad(gatherAndCombine(pf.snGrad()()));
443 Field<Type> refValue(gatherAndCombine(pf.refValue()));
444 Field<Type> refGrad(gatherAndCombine(pf.refGrad()));
445 scalarField valueFraction(gatherAndCombine(pf.valueFraction()));
456 << valueFraction[facei] <<
nl;
463 Field<Type> value(gatherAndCombine(bf[patchi]));
464 Field<Type>
snGrad(gatherAndCombine(bf[patchi].
snGrad()()));