/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . \*---------------------------------------------------------------------------*/ #include "fvMeshDistribute.H" #include "polyTopoChangeMap.H" #include "processorFvPatchField.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template void Foam::fvMeshDistribute::printFieldInfo(const fvMesh& mesh) { const UPtrList fields ( mesh.fields(false, fvMesh::curGeometryFields) ); forAll(fields, i) { const GeoField& field = fields[i]; Pout<< "Field:" << field.name() << " internal size:" << field.size() << endl; forAll(field.boundaryField(), patchi) { Pout<< " " << patchi << ' ' << field.boundaryField()[patchi].patch().name() << ' ' << field.boundaryField()[patchi].type() << ' ' << field.boundaryField()[patchi].size() << endl; } } } template void Foam::fvMeshDistribute::saveBoundaryFields ( PtrList& bfields ) const { // Save whole boundary field const UPtrList fields ( mesh_.fields(false, fvMesh::curGeometryFields) ); bfields.setSize(fields.size()); forAll(fields, i) { const GeoField& field = fields[i]; bfields.set ( i, new typename GeoField::BoundaryField ( field.boundaryField(), field ) ); } } template void Foam::fvMeshDistribute::mapBoundaryFields ( const polyTopoChangeMap& map, const PtrList& oldBfields ) { // Map boundary field const labelList& oldPatchStarts = map.oldPatchStarts(); const labelList& faceMap = map.faceMap(); UPtrList fields ( mesh_.fields(false, fvMesh::curGeometryFields) ); forAll(fields, i) { GeoField& field = fields[i]; typename GeoField::BoundaryField& bfield = field.boundaryFieldRef(); const typename GeoField::BoundaryField& oldBfield = oldBfields[i]; // Pull from old boundary field into bfield. forAll(bfield, patchi) { typename GeoField::PatchField& patchField = bfield[patchi]; label facei = patchField.patch().start(); forAll(patchField, i) { label oldFacei = faceMap[facei++]; // Find patch and local patch face oldFacei was in. forAll(oldPatchStarts, oldPatchi) { label oldLocalI = oldFacei - oldPatchStarts[oldPatchi]; if ( oldLocalI >= 0 && oldLocalI < oldBfield[oldPatchi].size() ) { patchField[i] = oldBfield[oldPatchi][oldLocalI]; } } } } } } template void Foam::fvMeshDistribute::initMapExposedFaces ( PtrList>& ifields ) const { const UPtrList> fields ( mesh_.fields>(false, fvMesh::curGeometryFields) ); ifields.setSize(fields.size()); forAll(fields, i) { ifields.set(i, Field(mesh_.nFaces())); const SurfaceField& field = fields[i]; SubList(ifields[i], field.primitiveField().size()) = field.primitiveField(); forAll(field.boundaryField(), patchi) { const fvsPatchField& pfield = field.boundaryField()[patchi]; SubList(ifields[i], pfield.size(), pfield.patch().start()) = pfield; } } } template void Foam::fvMeshDistribute::mapExposedFaces ( const polyTopoChangeMap& map, const PtrList>& oldFields ) { UPtrList> fields ( mesh_.fields>(false, fvMesh::curGeometryFields) ); forAll(fields, i) { SurfaceField& field = fields[i]; const Field& oldField = oldFields[i]; const bool negateIfFlipped = isFlux(field); forAll(field.boundaryField(), patchi) { fvsPatchField& patchField = field.boundaryFieldRef()[patchi]; forAll(patchField, i) { const label facei = patchField.patch().start()+i; const label oldFacei = map.faceMap()[facei]; if (oldFacei < map.nOldInternalFaces()) { if (negateIfFlipped && map.flipFaceFlux().found(facei)) { patchField[i] = flipOp()(oldField[oldFacei]); } else { patchField[i] = oldField[oldFacei]; } } else { patchField[i] = oldField[oldFacei]; } } } } } template void Foam::fvMeshDistribute::correctProcessorPatchFields() { UPtrList fields ( mesh_.fields(false, fvMesh::curGeometryFields) ); // Ensure the deltaCoeffs are available for constraint patch evaluation mesh_.deltaCoeffs(); forAll(fields, i) { GeoField& field = fields[i]; typename GeoField::BoundaryField& bfield = field.boundaryFieldRef(); if ( Pstream::defaultCommsType == Pstream::commsTypes::blocking || Pstream::defaultCommsType == Pstream::commsTypes::nonBlocking ) { label nReq = Pstream::nRequests(); forAll(bfield, patchi) { if (isA(bfield[patchi].patch().poly())) { bfield[patchi].initEvaluate(Pstream::defaultCommsType); } } // Block for any outstanding requests if ( Pstream::parRun() && Pstream::defaultCommsType == Pstream::commsTypes::nonBlocking ) { Pstream::waitRequests(nReq); } forAll(bfield, patchi) { if (isA(bfield[patchi].patch().poly())) { bfield[patchi].evaluate(Pstream::defaultCommsType); } } } else if (Pstream::defaultCommsType == Pstream::commsTypes::scheduled) { const lduSchedule& patchSchedule = mesh_.globalData().patchSchedule(); forAll(patchSchedule, patchEvali) { if ( isA ( bfield[patchSchedule[patchEvali].patch].patch().poly() ) ) { if (patchSchedule[patchEvali].init) { bfield[patchSchedule[patchEvali].patch] .initEvaluate(Pstream::commsTypes::scheduled); } else { bfield[patchSchedule[patchEvali].patch] .evaluate(Pstream::commsTypes::scheduled); } } } } } } template void Foam::fvMeshDistribute::sendFields ( const label domain, const wordList& fieldNames, const fvMeshSubset& subsetter, Ostream& toNbr ) { // Send fields. Note order supplied so we can receive in exactly the same // order. // Note that field gets written as entry in dictionary so we // can construct from subdictionary. // (since otherwise the reading as-a-dictionary mixes up entries from // consecutive fields) // The dictionary constructed is: // volScalarField // { // p {internalField ..; boundaryField ..;} // k {internalField ..; boundaryField ..;} // } // volVectorField // { // U {internalField ... } // } // volVectorField {U {internalField ..; boundaryField ..;}} toNbr << GeoField::typeName << token::NL << token::BEGIN_BLOCK << token::NL; forAll(fieldNames, i) { if (debug) { Pout<< "Subsetting field " << fieldNames[i] << " for domain:" << domain << endl; } // Send all fieldNames. This has to be exactly the same set as is // being received! const GeoField& field = subsetter.baseMesh().lookupObject(fieldNames[i]); tmp tsubfield = subsetter.interpolate(field); toNbr << fieldNames[i] << token::NL << token::BEGIN_BLOCK << tsubfield << token::NL << token::END_BLOCK << token::NL; } toNbr << token::END_BLOCK << token::NL; } template void Foam::fvMeshDistribute::receiveFields ( const label domain, const wordList& fieldNames, typename GeoField::Mesh& mesh, PtrList& fields, const dictionary& fieldDicts ) { if (debug) { Pout<< "Receiving fields " << fieldNames << " from domain:" << domain << endl; } fields.setSize(fieldNames.size()); forAll(fieldNames, i) { if (debug) { Pout<< "Constructing field " << fieldNames[i] << " from domain:" << domain << endl; } fields.set ( i, new GeoField ( IOobject ( fieldNames[i], mesh.db().time().name(), mesh.db(), IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, fieldDicts.subDict(fieldNames[i]) ) ); } } // ************************************************************************* //