From 6e573ad7e83d1e928cc36ccfc23355f546a4ae8d Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Sun, 3 Apr 2016 10:26:05 +0100 Subject: [PATCH] UList: Rationalize assignment (shallow-copy vs deep-copy) //- Disallow default shallow-copy assignment // // Assignment of UList may need to be either shallow (copy pointer) // or deep (copy elements) depending on context or the particular type // of list derived from UList and it is confusing and prone to error // for the default assignment to be either. The solution is to // disallow default assignment and provide separate 'shallowCopy' and // 'deepCopy' member functions. void operator=(const UList&) = delete; //- Copy the pointer held by the given UList. inline void shallowCopy(const UList&); //- Copy elements of the given UList. void deepCopy(const UList&); --- .../CompactListList/Test-CompactListList.C | 4 +-- .../test/globalMeshData/Test-globalMeshData.C | 14 ++++------ .../preProcessing/setFields/setFields.C | 4 +-- .../viewFactorsGen/viewFactorsGen.C | 8 +++--- .../containers/Lists/SubList/SubList.H | 3 +++ .../containers/Lists/SubList/SubListI.H | 9 ++++++- src/OpenFOAM/containers/Lists/UList/UList.C | 2 +- src/OpenFOAM/containers/Lists/UList/UList.H | 26 ++++++++++++++++--- src/OpenFOAM/containers/Lists/UList/UListI.H | 8 ++++++ .../SlicedGeometricField.C | 16 ++++++------ .../LUscalarMatrix/LUscalarMatrixTemplates.C | 2 +- .../GAMG/GAMGSolverAgglomerateMatrix.C | 12 +++------ .../lduMatrix/solvers/GAMG/GAMGSolverSolve.C | 2 +- .../globalMeshData/globalIndexTemplates.C | 6 ++--- .../PrimitivePatch/PrimitivePatch.C | 2 +- src/Pstream/dummy/UPstream.C | 2 +- src/Pstream/mpi/UPstream.C | 2 +- .../fvMeshDistribute/fvMeshDistribute.C | 14 +++++----- .../basic/sliced/slicedFvPatchField.C | 8 +++--- .../basic/sliced/slicedFvsPatchField.C | 8 +++--- .../volPointInterpolate.C | 2 +- .../CellZoneInjection/CellZoneInjection.C | 10 +++---- .../clouds/Templates/SprayCloud/SprayCloudI.H | 4 +-- .../AMIInterpolationParallelOps.C | 4 +-- .../simpleGeomDecomp/simpleGeomDecomp.C | 14 +++++----- src/renumber/SloanRenumber/SloanRenumber.C | 4 +-- .../meshToMesh/meshToMeshParallelOps.C | 13 ++++------ .../sampledPatchInternalFieldTemplates.C | 2 +- .../sampledTriSurfaceMeshTemplates.C | 2 +- src/surfMesh/surfMesh/surfMesh.C | 6 ++--- .../radiationModels/viewFactor/viewFactor.C | 9 +++---- 31 files changed, 122 insertions(+), 100 deletions(-) diff --git a/applications/test/CompactListList/Test-CompactListList.C b/applications/test/CompactListList/Test-CompactListList.C index 6d0a26676a..9baf498faf 100644 --- a/applications/test/CompactListList/Test-CompactListList.C +++ b/applications/test/CompactListList/Test-CompactListList.C @@ -56,8 +56,8 @@ int main(int argc, char *argv[]) rowSizes[1] = row1.size(); cll1.resize(rowSizes); - cll1[0].assign(row0); //note: operator= will not work since UList - cll1[1].assign(row1); + cll1[0].deepCopy(row0); + cll1[1].deepCopy(row1); Info<< "cll1:" << cll1 << endl; forAll(cll1.m(), i) diff --git a/applications/test/globalMeshData/Test-globalMeshData.C b/applications/test/globalMeshData/Test-globalMeshData.C index c6b2d142e7..eab4500ebe 100644 --- a/applications/test/globalMeshData/Test-globalMeshData.C +++ b/applications/test/globalMeshData/Test-globalMeshData.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -64,10 +64,8 @@ int main(int argc, char *argv[]) // Create field with my local data pointField coords(globalPointSlavesMap.constructSize()); - SubList(coords, coupledPatch.nPoints()).assign - ( - coupledPatch.localPoints() - ); + SubList(coords, coupledPatch.nPoints()) = + coupledPatch.localPoints(); // Exchange data. Apply positional transforms. globalPointSlavesMap.distribute @@ -185,8 +183,7 @@ int main(int argc, char *argv[]) label nBnd = mesh.nFaces()-mesh.nInternalFaces(); pointField fc(globalPointBoundaryFacesMap.constructSize()); - SubList(fc, nBnd).assign - ( + SubList(fc, nBnd) = primitivePatch ( SubList @@ -196,8 +193,7 @@ int main(int argc, char *argv[]) mesh.nInternalFaces() ), mesh.points() - ).faceCentres() - ); + ).faceCentres(); // Exchange data globalPointBoundaryFacesMap.distribute diff --git a/applications/utilities/preProcessing/setFields/setFields.C b/applications/utilities/preProcessing/setFields/setFields.C index eedce844bc..9570756b4f 100644 --- a/applications/utilities/preProcessing/setFields/setFields.C +++ b/applications/utilities/preProcessing/setFields/setFields.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -240,7 +240,7 @@ bool setFaceFieldType field.boundaryField()[patchi].size(), field.boundaryField()[patchi].patch().start() - mesh.nInternalFaces() - ).assign(field.boundaryField()[patchi]); + ) = field.boundaryField()[patchi]; } // Override diff --git a/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C b/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C index defc6fb870..cdafdf3b20 100644 --- a/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C +++ b/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C @@ -424,14 +424,14 @@ int main(int argc, char *argv[]) ( availablePoints, upp.faceCentres().size() - ).assign(upp.faceCentres()); + ) = upp.faceCentres(); SubList ( availablePoints, upp.localPoints().size(), upp.faceCentres().size() - ).assign(upp.localPoints()); + ) = upp.localPoints(); point cfo = cf; scalar dist = GREAT; @@ -592,8 +592,8 @@ int main(int argc, char *argv[]) DynamicList