diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertAreaFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertAreaFields.H index bdeba32c5c..d72c251c27 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertAreaFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertAreaFields.H @@ -8,20 +8,7 @@ Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 . + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. Description Code chunk for converting finite-area - included by foamToVTK. diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertLagrangian.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertLagrangian.H index de8c9c5d7c..7233b0cacf 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertLagrangian.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertLagrangian.H @@ -8,20 +8,7 @@ Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 . + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. Description Code chunk for post-processing conversion of cloud(s) to VTK PolyData diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertProcessorPatches.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertProcessorPatches.H index 0b00f38122..a220bfecdc 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertProcessorPatches.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertProcessorPatches.H @@ -5,23 +5,10 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 . + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. Description Code chunk for converting volume fields on processor boundaries, @@ -145,7 +132,8 @@ Description patchWriters, meshProxy, objects, - true // syncPar + true, // syncPar + nullptr // no field cache (object registry) ); // End CellData is implicit diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertSurfaceFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertSurfaceFields.H index 6005ffa4a6..e44966991e 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertSurfaceFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertSurfaceFields.H @@ -8,20 +8,7 @@ Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 . + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. Description Code chunk for post-processing surface fields to VTK PolyData diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertTopoSet.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertTopoSet.H index d939edbd22..547f5b0e8e 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertTopoSet.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertTopoSet.H @@ -8,20 +8,7 @@ Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 . + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. Description Code chunk for converting face and point sets - included by foamToVTK. diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertVolumeFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertVolumeFields.H index d224b5d01c..90e5be85cb 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertVolumeFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertVolumeFields.H @@ -5,23 +5,10 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 . + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. Description Code chunk for converting volume and dimensioned fields @@ -56,8 +43,14 @@ Description ); - reportFields::volume(Info, objects); - reportFields::internal(Info, objects); + if (doInternal || doBoundary) + { + reportFields::volume(Info, objects); + } + if (doInternal) + { + reportFields::internal(Info, objects); + } // Setup for the vtm writer. @@ -269,6 +262,26 @@ Description patchInterps.resize(nPatchInterps); } + // With point-interpolation, cache fields to avoid multiple re-reading + std::unique_ptr cacheFieldsPtr; + + if (doPointValues && (nVolFields || nDimFields)) + { + cacheFieldsPtr.reset + ( + new objectRegistry + ( + IOobject + ( + "foamToVTK::volume", + runTime.timeName(), + runTime, + IOobject::NO_REGISTER + ) + ) + ); + } + // CellData { @@ -314,7 +327,8 @@ Description patchWriters, meshProxy, objects, - true // syncPar + true, // syncPar + cacheFieldsPtr.get() ); writeAllDimFields @@ -322,7 +336,8 @@ Description internalWriter, meshProxy, objects, - true // syncPar + true, // syncPar + cacheFieldsPtr.get() ); // End CellData is implicit @@ -373,7 +388,8 @@ Description patchWriters, patchInterps, meshProxy, objects, - true // syncPar + true, // syncPar + cacheFieldsPtr.get() ); writeAllDimFields @@ -381,7 +397,8 @@ Description internalWriter, pInterp, meshProxy, objects, - true // syncPar + true, // syncPar + cacheFieldsPtr.get() ); writeAllPointFields diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.C index 3f8311b1c4..f160eeb027 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -49,14 +49,47 @@ Foam::tmp Foam::getField ( const IOobject* io, const fvMeshSubsetProxy& proxy, - const bool syncPar + const bool syncPar, + objectRegistry* cache ) { - return - proxy.interpolate + tmp tfield; + + if (io) + { + const word& fieldName = io->name(); + + if (cache) + { + // Get reference from cache if possible + tfield.cref(cache->cfindObject(fieldName)); + + if (tfield) + { + return tfield; + } + } + + tfield = proxy.interpolate ( getField(io, proxy.baseMesh(), syncPar) ); + + if (tfield && cache) + { + // Move field to the cache + IOobject newIO(tfield(), *cache); + newIO.readOpt(IOobject::NO_READ); + newIO.writeOpt(IOobject::NO_WRITE); + + tfield.ref().checkOut(); // Paranoid + cache->store(new GeoField(newIO, tfield)); + + tfield.cref(cache->cfindObject(fieldName)); + } + } + + return tfield; } @@ -71,7 +104,12 @@ Foam::tmp Foam::getField { // Can do something with syncPar on failure ... - return getField(objects.findObject(fieldName), mesh, syncPar); + return getField + ( + objects.findObject(fieldName), + mesh, + syncPar + ); } @@ -81,12 +119,19 @@ Foam::tmp Foam::getField const fvMeshSubsetProxy& proxy, const IOobjectList& objects, const word& fieldName, - const bool syncPar + const bool syncPar, + objectRegistry* cache ) { // Can do something with syncPar on failure ... - return getField(objects.findObject(fieldName), proxy, syncPar); + return getField + ( + objects.findObject(fieldName), + proxy, + syncPar, + cache + ); } diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.H index f5f15321c5..2b308d8621 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,10 +35,11 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef Foam_readFields_H -#define Foam_readFields_H +#ifndef FoamToVTK_readFields_H +#define FoamToVTK_readFields_H #include "fvMeshSubsetProxy.H" +#include "objectRegistry.H" #include "IOobjectList.H" #include "PtrList.H" @@ -63,7 +64,8 @@ tmp getField ( const IOobject* io, const fvMeshSubsetProxy& proxy, - const bool syncPar + const bool syncPar, + objectRegistry* cache = nullptr ); @@ -78,14 +80,17 @@ tmp getField ); -//- Get the named field from the objects and subset it, or return nullptr +//- Return the named field from the optional cache (if found), +//- or get it from the objects and subset it (add to cache). +//- Return nullptr if nothing worked. template tmp getField ( const fvMeshSubsetProxy& proxy, const IOobjectList& objects, const word& fieldName, - const bool syncPar + const bool syncPar, + objectRegistry* cache = nullptr ); diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/writeAreaFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/writeAreaFields.H index d8111f5f7a..2c216e7a0a 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/writeAreaFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/writeAreaFields.H @@ -5,38 +5,19 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 . - -InNamespace - Foam + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. Description - Read finite-area fields from disk + Code chunk for reading finite-area fields from disk and write with vtk::uindirectPatchGeoFieldsWriter -SourceFiles - writeAreaFields.H - \*---------------------------------------------------------------------------*/ -#ifndef writeAreaFields_H -#define writeAreaFields_H +#ifndef FoamToVTK_writeAreaFields_H +#define FoamToVTK_writeAreaFields_H #include "readFields.H" #include "foamVtkIndPatchGeoFieldsWriter.H" @@ -49,25 +30,6 @@ namespace Foam // Writer type for finite-area mesh + fields typedef vtk::uindirectPatchGeoFieldsWriter vtkWriterType_areaMesh; -template -bool writeAreaField -( - vtkWriterType_areaMesh& writer, - const tmp& tfield -) -{ - if (tfield) - { - writer.write(tfield()); - tfield.clear(); - - return true; - } - - return false; -} - - template label writeAreaFields ( @@ -81,15 +43,14 @@ label writeAreaFields for (const word& fieldName : objects.sortedNames()) { - if - ( - writeAreaField - ( - writer, - getField(mesh, objects, fieldName, syncPar) - ) - ) + tmp tfield = + getField(mesh, objects, fieldName, syncPar); + + if (tfield) { + writer.write(tfield()); + + tfield.clear(); ++count; } } diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/writeDimFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/writeDimFields.H index 45e8d79476..eb8766f362 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/writeDimFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/writeDimFields.H @@ -5,38 +5,19 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 . - -InNamespace - Foam + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. Description - Read dimensioned fields from disk + Code chunk for reading dimensioned fields from disk and write with vtk::internalWriter -SourceFiles - writeDimFields.H - \*---------------------------------------------------------------------------*/ -#ifndef writeDimFields_H -#define writeDimFields_H +#ifndef FoamToVTK_writeDimFields_H +#define FoamToVTK_writeDimFields_H #include "readFields.H" #include "foamVtkInternalWriter.H" @@ -46,77 +27,31 @@ SourceFiles namespace Foam { -template -bool writeDimField -( - autoPtr& internalWriter, - const tmp& tfield -) -{ - if (!tfield) - { - return false; - } - - const auto& field = tfield(); - - if (internalWriter) - { - internalWriter->write(field); - } - - tfield.clear(); - return true; -} - - -template -bool writeDimField -( - autoPtr& internalWriter, - const autoPtr& pInterp, - const tmp& tfield -) -{ - if (!tfield) - { - return false; - } - - const auto& field = tfield(); - - if (internalWriter && pInterp) - { - internalWriter->write(field, *pInterp); - } - - tfield.clear(); - return true; -} - - template label writeDimFields ( autoPtr& internalWriter, const fvMeshSubsetProxy& proxy, const IOobjectList& objects, - const bool syncPar + const bool syncPar, + objectRegistry* cache ) { + // Sanity test + if (!internalWriter) return 0; + label count = 0; for (const word& fieldName : objects.sortedNames()) { - if - ( - writeDimField - ( - internalWriter, - getField(proxy, objects, fieldName, syncPar) - ) - ) + tmp tfield = + getField(proxy, objects, fieldName, syncPar, cache); + + if (tfield) { + internalWriter->write(tfield()); + + tfield.clear(); ++count; } } @@ -133,22 +68,25 @@ label writeDimFields const fvMeshSubsetProxy& proxy, const IOobjectList& objects, - const bool syncPar + const bool syncPar, + objectRegistry* cache ) { + // Sanity test + if (!internalWriter || !pInterp) return 0; + label count = 0; for (const word& fieldName : objects.sortedNames()) { - if - ( - writeDimField - ( - internalWriter, pInterp, - getField(proxy, objects, fieldName, syncPar) - ) - ) + tmp tfield = + getField(proxy, objects, fieldName, syncPar, cache); + + if (tfield) { + internalWriter->write(tfield(), *pInterp); + + tfield.clear(); ++count; } } @@ -163,9 +101,13 @@ label writeAllDimFields const fvMeshSubsetProxy& proxy, const IOobjectList& objects, - const bool syncPar + const bool syncPar, + objectRegistry* cache ) { + // Sanity test + if (!internalWriter) return 0; + #undef foamToVtk_WRITE_FIELD #define foamToVtk_WRITE_FIELD(FieldType) \ writeDimFields \ @@ -173,7 +115,8 @@ label writeAllDimFields internalWriter, \ proxy, \ objects, \ - syncPar \ + syncPar, \ + cache \ ) label count = 0; @@ -195,9 +138,13 @@ label writeAllDimFields const fvMeshSubsetProxy& proxy, const IOobjectList& objects, - const bool syncPar + const bool syncPar, + objectRegistry* cache ) { + // Sanity test + if (!internalWriter || !pInterp) return 0; + #undef foamToVtk_WRITE_FIELD #define foamToVtk_WRITE_FIELD(FieldType) \ writeDimFields \ @@ -205,7 +152,8 @@ label writeAllDimFields internalWriter, pInterp, \ proxy, \ objects, \ - syncPar \ + syncPar, \ + cache \ ) label count = 0; diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/writePointFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/writePointFields.H index cb1e311f4f..7b84181d75 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/writePointFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/writePointFields.H @@ -5,38 +5,19 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 . - -InNamespace - Foam + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. Description - Read point fields from disk + Code chunk for reading point fields from disk and write with vtk::internalWriter and vtk::patchWriter -SourceFiles - writePointFields.H - \*---------------------------------------------------------------------------*/ -#ifndef writePointFields_H -#define writePointFields_H +#ifndef FoamToVTK_writePointFields_H +#define FoamToVTK_writePointFields_H #include "readFields.H" #include "foamVtkInternalWriter.H" @@ -57,6 +38,9 @@ bool writePointField const fvMeshSubsetProxy& proxy ) { + // Sanity test + if (!internalWriter && patchWriters.empty()) return false; + if (!tfield) { return false; @@ -113,6 +97,9 @@ label writePointFields const bool syncPar ) { + // Sanity test + if (!internalWriter && patchWriters.empty()) return 0; + label count = 0; for (const word& fieldName : objects.sortedNames()) @@ -146,6 +133,9 @@ label writeAllPointFields const bool syncPar ) { + // Sanity test + if (!internalWriter && patchWriters.empty()) return 0; + const pointMesh& ptMesh = pointMesh::New(proxy.baseMesh()); #undef foamToVtk_WRITE_FIELD diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/writeSurfaceFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/writeSurfaceFields.H index 530ffd2d28..ce6f59c8e8 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/writeSurfaceFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/writeSurfaceFields.H @@ -8,30 +8,11 @@ Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 . - -InNamespace - Foam + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. Description Write surface fields from volume mesh -SourceFiles - writeSurfaceFields.H - \*---------------------------------------------------------------------------*/ #ifndef writeSurfaceFields_H diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/writeVolFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/writeVolFields.H index 6df3d101a3..8a04c3ddf4 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/writeVolFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/writeVolFields.H @@ -5,38 +5,19 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 . - -InNamespace - Foam + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. Description - Read volume fields from disk + Code chunk for reading volume fields from disk and write with vtk::internalWriter and vtk::patchWriter -SourceFiles - writeVolFields.H - \*---------------------------------------------------------------------------*/ -#ifndef writeVolFields_H -#define writeVolFields_H +#ifndef FoamToVTK_writeVolFields_H +#define FoamToVTK_writeVolFields_H #include "readFields.H" #include "foamVtkInternalWriter.H" @@ -47,79 +28,6 @@ SourceFiles namespace Foam { -template -bool writeVolField -( - autoPtr& internalWriter, - UPtrList& patchWriters, - const tmp& tfield -) -{ - if (!tfield) - { - return false; - } - - const auto& field = tfield(); - - // Internal - if (internalWriter) - { - internalWriter->write(field); - } - - // Boundary - for (vtk::patchWriter& writer : patchWriters) - { - writer.write(field); - } - - tfield.clear(); - return true; -} - - -template -bool writeVolField -( - autoPtr& internalWriter, - const autoPtr& pInterp, - - UPtrList& patchWriters, - const UPtrList>& patchInterps, - - const tmp& tfield -) -{ - if (!tfield) - { - return false; - } - - const auto& field = tfield(); - - // Internal - if (internalWriter && pInterp) - { - internalWriter->write(field, *pInterp); - } - - // Boundary - label writeri = 0; - for (vtk::patchWriter& writer : patchWriters) - { - if (writeri < patchInterps.size() && patchInterps.set(writeri)) - { - writer.write(field, patchInterps[writeri]); - } - ++writeri; - } - - tfield.clear(); - return true; -} - - template label writeVolFields ( @@ -127,23 +35,35 @@ label writeVolFields UPtrList& patchWriters, const fvMeshSubsetProxy& proxy, const IOobjectList& objects, - const bool syncPar + const bool syncPar, + objectRegistry* cache ) { + // Sanity test + if (!internalWriter && patchWriters.empty()) return 0; + label count = 0; for (const word& fieldName : objects.sortedNames()) { - if - ( - writeVolField - ( - internalWriter, - patchWriters, - getField(proxy, objects, fieldName, syncPar) - ) - ) + tmp tfield = + getField(proxy, objects, fieldName, syncPar, cache); + + if (tfield) { + // Internal + if (internalWriter) + { + internalWriter->write(tfield()); + } + + // Boundary + for (vtk::patchWriter& writer : patchWriters) + { + writer.write(tfield()); + } + + tfield.clear(); ++count; } } @@ -163,23 +83,47 @@ label writeVolFields const fvMeshSubsetProxy& proxy, const IOobjectList& objects, - const bool syncPar + const bool syncPar, + objectRegistry* cache ) { + // Sanity test + if + ( + (!internalWriter || !pInterp) + && (patchWriters.empty() || patchInterps.empty()) + ) + { + return 0; + } + label count = 0; for (const word& fieldName : objects.sortedNames()) { - if - ( - writeVolField - ( - internalWriter, pInterp, - patchWriters, patchInterps, - getField(proxy, objects, fieldName, syncPar) - ) - ) + tmp tfield = + getField(proxy, objects, fieldName, syncPar, cache); + + if (tfield) { + // Internal + if (internalWriter && pInterp) + { + internalWriter->write(tfield(), *pInterp); + } + + // Boundary + label writeri = 0; + for (vtk::patchWriter& writer : patchWriters) + { + if (writeri < patchInterps.size() && patchInterps.set(writeri)) + { + writer.write(tfield(), patchInterps[writeri]); + } + ++writeri; + } + + tfield.clear(); ++count; } } @@ -195,9 +139,13 @@ label writeAllVolFields const fvMeshSubsetProxy& proxy, const IOobjectList& objects, - const bool syncPar + const bool syncPar, + objectRegistry* cache ) { + // Sanity test + if (!internalWriter && patchWriters.empty()) return 0; + #undef foamToVtk_WRITE_FIELD #define foamToVtk_WRITE_FIELD(FieldType) \ writeVolFields \ @@ -206,7 +154,8 @@ label writeAllVolFields patchWriters, \ proxy, \ objects, \ - syncPar \ + syncPar, \ + cache \ ) label count = 0; @@ -231,7 +180,8 @@ label writeAllVolFields const fvMeshSubsetProxy& proxy, const IOobjectList& objects, - const bool syncPar + const bool syncPar, + objectRegistry* cache ) { #undef foamToVtk_WRITE_FIELD @@ -242,7 +192,8 @@ label writeAllVolFields patchWriters, patchInterps, \ proxy, \ objects, \ - syncPar \ + syncPar, \ + cache \ )