From 71979accf5d0830de3fa5360b20fa9d37576cbd4 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Wed, 12 Apr 2023 11:29:22 +0100 Subject: [PATCH] PrimitiveOldTimePatch: Fix construction from null reference --- src/OpenFOAM/db/typeInfo/typeInfo.H | 8 +++++++- .../PrimitiveOldTimePatch/PrimitiveOldTimePatch.C | 6 ++++-- .../PrimitiveOldTimePatch/PrimitiveOldTimePatch.H | 9 ++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/OpenFOAM/db/typeInfo/typeInfo.H b/src/OpenFOAM/db/typeInfo/typeInfo.H index 01af6c7201..b9a2257c0d 100644 --- a/src/OpenFOAM/db/typeInfo/typeInfo.H +++ b/src/OpenFOAM/db/typeInfo/typeInfo.H @@ -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 @@ -55,6 +55,7 @@ Description #include "error.H" #include "className.H" +#include #include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -151,6 +152,11 @@ inline word typedName(Name name) } +//- Determine whether a type is a reference +template +constexpr bool isRef = std::is_reference::value; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/meshTools/PrimitiveOldTimePatch/PrimitiveOldTimePatch.C b/src/meshTools/PrimitiveOldTimePatch/PrimitiveOldTimePatch.C index 3fa039db98..ad2e248b74 100644 --- a/src/meshTools/PrimitiveOldTimePatch/PrimitiveOldTimePatch.C +++ b/src/meshTools/PrimitiveOldTimePatch/PrimitiveOldTimePatch.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -36,7 +36,8 @@ Foam::PrimitiveOldTimePatch::PrimitiveOldTimePatch ) : PrimitivePatch(faces, points), - points0_(points0), + points0Ptr_(isRef ? nullptr : new Field(points0)), + points0_(isRef ? points0 : points0Ptr_()), patch0Ptr_(new patch0Type(faces, points0_)), localPoints0Ptr_(nullptr) {} @@ -64,6 +65,7 @@ Foam::PrimitiveOldTimePatch::PrimitiveOldTimePatch ) : PrimitivePatch(faces, points), + points0Ptr_(nullptr), points0_(NullObjectRef>()), patch0Ptr_(nullptr), localPoints0Ptr_(nullptr) diff --git a/src/meshTools/PrimitiveOldTimePatch/PrimitiveOldTimePatch.H b/src/meshTools/PrimitiveOldTimePatch/PrimitiveOldTimePatch.H index e08271688d..8daf3e184e 100644 --- a/src/meshTools/PrimitiveOldTimePatch/PrimitiveOldTimePatch.H +++ b/src/meshTools/PrimitiveOldTimePatch/PrimitiveOldTimePatch.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -85,15 +85,18 @@ private: PrimitivePatch < typename UFaceList::type, - const PointFieldType& + const Field& > patch0Type; // Private Data + //- Stored old-time points + autoPtr> points0Ptr_; + //- Reference to global list of old-time points - PointField points0_; + const Field& points0_; //- Engine for calculating old-time geometry. Note: Methods that // generate topology should not be called here. The base patch should