BUG: sampledMeshSurface sampling on "empty" patch fails

- requires a field size check when copying into the flat boundary
This commit is contained in:
Mark Olesen
2024-05-02 09:44:47 +02:00
parent e651d63566
commit 0ef7589979

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd. Copyright (C) 2016-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -39,7 +39,11 @@ Foam::sampledMeshedSurface::sampleOnFaces
{ {
const Type deflt const Type deflt
( (
defaultValues_.getOrDefault<Type>(sampler.psi().name(), Zero) defaultValues_.getOrDefault<Type>
(
sampler.psi().name(),
Foam::zero{}
)
); );
const labelList& elements = sampleElements_; const labelList& elements = sampleElements_;
@ -71,13 +75,16 @@ Foam::sampledMeshedSurface::sampleOnFaces
const polyBoundaryMesh& pbm = mesh().boundaryMesh(); const polyBoundaryMesh& pbm = mesh().boundaryMesh();
Field<Type> bVals(mesh().nBoundaryFaces(), Zero); Field<Type> bVals(mesh().nBoundaryFaces(), deflt);
const auto& bField = sampler.psi().boundaryField(); const auto& bField = sampler.psi().boundaryField();
forAll(bField, patchi) forAll(bField, patchi)
{ {
SubList<Type>(bVals, pbm[patchi].range()) = bField[patchi]; // Note: restrict transcribing to actual size of the patch field
// - handles "empty" patch type etc.
const auto& pfld = bField[patchi];
SubList<Type>(bVals, pfld.size(), pbm[patchi].offset()) = pfld;
} }
// Sample within the flat boundary field // Sample within the flat boundary field
@ -109,7 +116,11 @@ Foam::sampledMeshedSurface::sampleOnPoints
{ {
const Type deflt const Type deflt
( (
defaultValues_.getOrDefault<Type>(interpolator.psi().name(), Zero) defaultValues_.getOrDefault<Type>
(
interpolator.psi().name(),
Foam::zero{}
)
); );
const labelList& elements = sampleElements_; const labelList& elements = sampleElements_;