From cd133a28f589c5eb48e53737e9a71f530b1192c0 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Wed, 20 Dec 2023 15:54:25 +0000 Subject: [PATCH 1/4] fvMeshTopoChangers::refiner: Fix hang in parallel This has required switching the order of dependence of the fvMesh geometry (i.e., Sf, Cf, and C), and the interpolation weights. The weights are now considered dependent on the geometry fields, and the geometry fields must therefore construct without reference to the weights. --- .../surfaceInterpolation/surfaceInterpolation.C | 12 ++++-------- .../refiner/fvMeshTopoChangersRefiner.C | 5 +---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/surfaceInterpolation/surfaceInterpolation.C b/src/finiteVolume/interpolation/surfaceInterpolation/surfaceInterpolation/surfaceInterpolation.C index 146dc770a8..44d46ada8b 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/surfaceInterpolation/surfaceInterpolation.C +++ b/src/finiteVolume/interpolation/surfaceInterpolation/surfaceInterpolation/surfaceInterpolation.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -158,15 +158,11 @@ void Foam::surfaceInterpolation::makeWeights() const surfaceScalarField& weights = *weights_; // Set local references to mesh data - // (note that we should not use fvMesh sliced fields at this point yet - // since this causes a loop when generating weighting factors in - // coupledFvPatchField evaluation phase) const labelUList& owner = mesh_.owner(); const labelUList& neighbour = mesh_.neighbour(); - - const vectorField& Cf = mesh_.faceCentres(); - const vectorField& C = mesh_.cellCentres(); - const vectorField& Sf = mesh_.faceAreas(); + const surfaceVectorField& Sf = mesh_.Sf(); + const surfaceVectorField& Cf = mesh_.Cf(); + const volVectorField& C = mesh_.C(); // ... and reference to the internal field of the weighting factors scalarField& w = weights.primitiveFieldRef(); diff --git a/src/fvMeshTopoChangers/refiner/fvMeshTopoChangersRefiner.C b/src/fvMeshTopoChangers/refiner/fvMeshTopoChangersRefiner.C index 8a8b3bc2e5..87091f9ae2 100644 --- a/src/fvMeshTopoChangers/refiner/fvMeshTopoChangersRefiner.C +++ b/src/fvMeshTopoChangers/refiner/fvMeshTopoChangersRefiner.C @@ -575,10 +575,7 @@ void Foam::fvMeshTopoChangers::refiner::refineUfs { const surfaceVectorField UfU ( - fvc::interpolate - ( - mesh().lookupObject(Uname) - ) + fvc::interpolate(mesh().lookupObject(Uname)) ); // Recalculate new internal faces. From f9b4027b05a0f77e59ad3e1d7ec5346bd386e50b Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Thu, 21 Dec 2023 09:10:07 +0000 Subject: [PATCH 2/4] vtkWriteOps: Protect against float overflow --- src/fileFormats/vtk/vtkWriteOps.C | 26 +++++----- src/fileFormats/vtk/vtkWriteOps.H | 19 +++++-- src/fileFormats/vtk/vtkWriteOpsI.H | 49 +++++++++++++++++++ .../vtk/vtkWritePolyDataTemplates.C | 13 +++-- 4 files changed, 86 insertions(+), 21 deletions(-) create mode 100644 src/fileFormats/vtk/vtkWriteOpsI.H diff --git a/src/fileFormats/vtk/vtkWriteOps.C b/src/fileFormats/vtk/vtkWriteOps.C index 67c2216d3d..a3dffc236c 100644 --- a/src/fileFormats/vtk/vtkWriteOps.C +++ b/src/fileFormats/vtk/vtkWriteOps.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -90,7 +90,7 @@ void Foam::vtkWriteOps::write os.write ( reinterpret_cast(fField.begin()), - fField.size()*sizeof(float) + fField.size()*sizeof(floatScalar) ); os << std::endl; @@ -228,7 +228,7 @@ void Foam::vtkWriteOps::writePointDataHeader void Foam::vtkWriteOps::insert(const scalar src, DynamicList& dest) { - dest.append(float(src)); + dest.append(cast(src)); } @@ -240,7 +240,7 @@ void Foam::vtkWriteOps::insert { for (direction cmpt = 0; cmpt < vector::nComponents; ++cmpt) { - dest.append(float(src[cmpt])); + dest.append(cast(src[cmpt])); } } @@ -253,7 +253,7 @@ void Foam::vtkWriteOps::insert { for (direction cmpt = 0; cmpt < sphericalTensor::nComponents; ++cmpt) { - dest.append(float(src[cmpt])); + dest.append(cast(src[cmpt])); } } @@ -264,12 +264,12 @@ void Foam::vtkWriteOps::insert DynamicList& dest ) { - dest.append(float(src.xx())); - dest.append(float(src.yy())); - dest.append(float(src.zz())); - dest.append(float(src.xy())); - dest.append(float(src.yz())); - dest.append(float(src.xz())); + dest.append(cast(src.xx())); + dest.append(cast(src.yy())); + dest.append(cast(src.zz())); + dest.append(cast(src.xy())); + dest.append(cast(src.yz())); + dest.append(cast(src.xz())); } @@ -281,7 +281,7 @@ void Foam::vtkWriteOps::insert { for (direction cmpt = 0; cmpt < tensor::nComponents; ++cmpt) { - dest.append(float(src[cmpt])); + dest.append(cast(src[cmpt])); } } @@ -301,7 +301,7 @@ void Foam::vtkWriteOps::insert { forAll(map, i) { - dest.append(float(source[map[i]])); + dest.append(cast(source[map[i]])); } } diff --git a/src/fileFormats/vtk/vtkWriteOps.H b/src/fileFormats/vtk/vtkWriteOps.H index 494c54f8fc..5643d3b8ff 100644 --- a/src/fileFormats/vtk/vtkWriteOps.H +++ b/src/fileFormats/vtk/vtkWriteOps.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -58,6 +58,17 @@ namespace vtkWriteOps //- Swap halves of word void swapWords(const label nWords, label* words32); + //- Cast an integer to the corresponding VTK write type. Does nothing. + inline label cast(const label& x); + + //- Cast a float to the corresponding VTK write type. Does nothing. + inline floatScalar cast(const floatScalar& x); + + //- Cast a scalar to the corresponding VTK write type. Clips to + // pTraits::max. + template + inline floatScalar cast(const Scalar& x); + //- Write header void writeHeader ( @@ -66,6 +77,7 @@ namespace vtkWriteOps const std::string& title ); + //- Write cell data header void writeCellDataHeader ( std::ostream&, @@ -73,6 +85,7 @@ namespace vtkWriteOps const label nFields ); + //- Write point data header void writePointDataHeader ( std::ostream&, @@ -80,7 +93,6 @@ namespace vtkWriteOps const label nFields ); - //- Write floats ascii or binary. // If binary optionally in-place swaps argument void write(std::ostream& os, const bool binary, List& fField); @@ -97,7 +109,6 @@ namespace vtkWriteOps // If binary optionally in-place swaps argument void write(std::ostream&, const bool, DynamicList