Fix/verified issues - #215
Conversation
|
Hello,
|
|
Hello,
1. the declaration should be external static ... -> The idea is there is a
unique gTolerance for the library
2. if the geometric mesh points to a computational mesh call DebugStop()
3. agreed
4. agreed
5. agreed
6. I havent checked.
7. agreed
8. fully agreed
…On Mon, Jul 27, 2026 at 5:08 PM pereiraalessandra ***@***.***> wrote:
Fix verified issues Summary
This PR fixes eight issues identified by an AI-assisted code analysis.
For each issue, the sections below describe:
- where the problem occurs;
- why the current behavior is incorrect or unsafe;
- what was changed.
------------------------------
1. SetTolerance() updated only one source file's copy of the variable
*File:* Topology/TPZTopologyUtils.h
Problem
gTolerance was defined as a namespace-scope static variable inside a
header:
static REAL gTolerance = ...;
At namespace scope, static gives the variable internal linkage.
Consequently, every .cpp file that includes the header gets its own
independent copy of gTolerance, instead of all of them sharing one.
SetTolerance() is implemented in TPZTopologyUtils.cpp, so it only ever
modified the copy that lives in that one .cpp file. Other users of
gTolerance, including its use as the default tolerance in
IsInParametricDomain(), are defined in different .cpp files and kept
reading their own unchanged copies.
As a result, calls to SetTolerance() were silently ignored by most of the
library.
Fix
Changed the definition to a C++17 inline variable:
inline REAL gTolerance = ...;
An inline variable may be defined in a header while still representing a
single object shared by every .cpp file that includes it, instead of one
copy per file.
------------------------------
2. Destroying a geometric mesh first left the computational mesh with a
dangling pointer
*File:* Mesh/pzgmesh.cpp
*Function:* TPZGeoMesh::~TPZGeoMesh()
Problem
TPZCompMesh and TPZGeoMesh maintain references to each other.
When a computational mesh is destroyed first, TPZCompMesh::~TPZCompMesh()
already notifies the associated geometric mesh by calling ResetReference()
.
The reverse case was not handled. TPZGeoMesh::~TPZGeoMesh() called
CleanUp() without clearing the corresponding reference stored by the
computational mesh.
If a geometric mesh was destroyed while an associated computational mesh
was still alive, the computational mesh retained a pointer to freed memory.
A subsequent access such as
TPZCompEl::Reference()
could eventually dereference the deleted geometric mesh through:
fMesh->Reference()->ElementVec()[...]
This resulted in undefined behavior.
Fix
Added the corresponding notification in TPZGeoMesh::~TPZGeoMesh():
if (fReference && fReference->Reference() == this) {
fReference->SetReference(nullptr);
}
------------------------------
3. Debug checks used the wrong preprocessor macro
*Files:*
- Shape/TPZShapeHDivConstant.cpp
- Shape/TPZShapeHDivOptimized.cpp
- Shape/TPZShapeHDiv.cpp
- Shape/TPZShapeHDivConstantBound.cpp
- Mesh/pzelchdiv.cpp
- Mesh/pzelchdivbound2.cpp
- Mesh/TPZCompElHDivDuplConnects.cpp
- Mesh/TPZCompElHDivDuplConnectsBound.cpp
- Material/Elasticity/TPZMixedElasticityND.cpp
Problem
The project uses PZDEBUG as its debug-build macro, but 11 consistency and
bounds-checking blocks across these files used:
#ifdef DEBUG
Since DEBUG is not defined by the project build configuration, these
blocks were never compiled, including in Debug builds.
Fix
Replaced all 11 occurrences with:
#ifdef PZDEBUG
------------------------------
4. TPZCreateApproximationSpace did not preserve its configured
approximation families when copied
*File:* Pre/pzcreateapproxspace.h
Problem
The manually implemented copy constructor and assignment operator did not
copy the following members:
fhdivfam
fh1fam
fhcurlfamfStyle
These members record the configured approximation-space families and style.
TPZCompMesh contains a TPZCreateApproximationSpace object and exposes
mesh cloning through Clone(). Therefore, cloning a mesh configured with a
non-default family, such as EHDivConstant, could produce an object whose
stored configuration reported the default family even though its
shape-function creation callbacks still reflected the original
configuration.
This left the copied object in an internally inconsistent state.
Fix
Replaced the hand-written copy operations with compiler-generated ones:
TPZCreateApproximationSpace(
const TPZCreateApproximationSpace ©) = default;
TPZCreateApproximationSpace &operator=(
const TPZCreateApproximationSpace ©) = default;
All members already have valid copy semantics. Using = default also
prevents future data members from being accidentally omitted from the copy
operations.
Also cleaned up three setters in the same header that had const as part
of a void return type, e.g.:
const void SetHDivFamily(HDivFamily fam){ ... }
changed to:
void SetHDivFamily(HDivFamily fam){ ... }
const has no effect on a void return type. This does not change how these
methods behave or are called.
------------------------------
5. TPZAnalysis could be shallow-copied, causing double deletion of fSolver
*Files:*
- Analysis/TPZAnalysis.h
- Post/pzpostprocanalysis.h
- Post/pzpostprocanalysis.cpp
Problem
class TPZAnalysis {
TPZSolver *fSolver;
void CleanUp() { delete fSolver; }
~TPZAnalysis() { CleanUp(); }
// no copy constructor / operator= declared
};
TPZAnalysis owns fSolver: it deletes it during cleanup and in its
destructor. But the class did not declare a copy constructor or operator=,
so the compiler generated its own. For a raw pointer member, that means
copying the address, not the object it points to:
TPZAnalysis a1;
a1.SetSolver(mySolver); // a1.fSolver points to address X
TPZAnalysis a2 = a1; // a2.fSolver ALSO points to address X
a1 and a2 are now two separate objects whose fSolver points to the same
TPZSolver. Each one still believes it owns that solver and will delete it
when destroyed. The one that is destroyed second ends up calling delete
on memory that the first one already freed (double free).
TPZPostProcAnalysis (a subclass of TPZAnalysis) also explicitly wrote its
own copy constructor and operator=, instead of just inheriting the unsafe
compiler-generated ones:
TPZPostProcAnalysis::TPZPostProcAnalysis(const TPZPostProcAnalysis ©)
: TPZLinearAnalysis(copy), fpMainMesh(0)
{
}
TPZPostProcAnalysis &TPZPostProcAnalysis::operator=(const TPZPostProcAnalysis ©)
{
SetCompMesh(0);
return *this;
}
The copy constructor calls TPZLinearAnalysis(copy), which copies the base
class TPZAnalysis and inherits the same double-free problem. The operator=
does not copy anything from copy at all (it just resets the current
object and ignores its argument).
Fix
Both classes now explicitly forbid copying, instead of allowing an unsafe
copy or hand-writing a broken one:
TPZAnalysis(const TPZAnalysis &) = delete;
TPZAnalysis &operator=(const TPZAnalysis &) = delete;
TPZPostProcAnalysis(const TPZPostProcAnalysis ©) = delete;
TPZPostProcAnalysis &operator=(const TPZPostProcAnalysis ©) = delete;
= delete tells the compiler to reject any attempt to copy one of these
objects.
No code in the current repository copies a TPZAnalysis or a
TPZPostProcAnalysis, so this change does not affect any existing
behavior. It only removes an operation that was never safe to use.
------------------------------
6. Wrong face index in the Fad<REAL> branch of TPZShapeHDivConstant
*File:* Shape/TPZShapeHDivConstant.cpp
Problem
The Fad<REAL> overload of TPZShapeHDivConstant::Shape() used:
data.fHCurl.fNumConnectShape[nedges]
inside a loop over the element facets.
Because the index did not include the current facet index i, every facet
used the kernel-function count associated with the first facet.
The corresponding REAL overload already used the correct expression:
data.fHCurl.fNumConnectShape[nedges + i]
This can misalign the function blocks and lead to incorrect shape
functions, incorrect automatic derivatives, or out-of-bounds matrix
accesses.
Fix
Changed:
data.fHCurl.fNumConnectShape[nedges]
to:
data.fHCurl.fNumConnectShape[nedges + i]
The Fad<REAL> branch now matches the indexing already used by the REAL
branch.
------------------------------
7. Tautological condition in TPZH1ApproxCreator::CreateBoundaryHDivSpace()
*File:* Pre/TPZH1ApproxCreator.cpp
Problem
The function contained the following condition:
if (fHybridType != HybridizationType::EStandard ||
fHybridType != HybridizationType::EStandardSquared) {
This expression is always true.
For any possible value of fHybridType, it must be different from at least
one of the two enum values. Consequently, the corresponding else branch
containing DebugStop() was unreachable.
Fix
Changed the comparisons from != to == while preserving ||:
if (fHybridType == HybridizationType::EStandard ||
fHybridType == HybridizationType::EStandardSquared) {
With the current call flow, fHybridType can only be EStandard or
EStandardSquared when execution reaches this function.
CheckSetupConsistency() already rejects ESemi, and CreateAtomicMeshes()
rejects ENone.
Therefore, this change does not alter the behavior of any currently valid
execution path. It only serves as a defensive check, ensuring that any
future unsupported or unhandled enum value is detected instead of being
silently treated as valid.
------------------------------
8. Missing braces made the control flow in CreateAtomicMeshes()
misleading and fragile
*File:* Pre/TPZH1ApproxCreator.cpp
Problem
The function contained:
if (HybridType() != HybridizationType::ENone)
meshvec[countMesh++] = CreateBoundaryHDivSpace();
meshvec[countMesh++] = CreateL2Space();
In C++, an if statement without braces controls only the immediately
following statement.
Therefore, despite the indentation, the code was interpreted as:
if (HybridType() != HybridizationType::ENone) {
meshvec[countMesh++] = CreateBoundaryHDivSpace();
}
meshvec[countMesh++] = CreateL2Space();
The current behavior is valid because ENone is rejected earlier in the
function. However, the misleading indentation made the intended control
flow unclear and left the code dependent on that earlier validation
remaining unchanged.
Fix
Added braces around the statement that is actually conditional:
if (HybridType() != HybridizationType::ENone) {
meshvec[countMesh++] = CreateBoundaryHDivSpace();
}
meshvec[countMesh++] = CreateL2Space();
This change clarifies the actual behavior without changing it.
------------------------------
You can view, comment on, or merge this pull request online at:
#215
Commit Summary
- 0825884
<0825884>
docs: add AI-generated codebase analysis
- 6ab7dd2
<6ab7dd2>
docs: shorten AI-analysis note in README
- d0e47bd
<d0e47bd>
Fix SetTolerance() not propagating across translation units
- 1699bff
<1699bff>
Fix TPZGeoMesh not clearing TPZCompMesh's reference when destroyed first
- 16ef4e6
<16ef4e6>
Fix dead #ifdef DEBUG blocks by renaming to #ifdef PZDEBUG
- 882bb6f
<882bb6f>
Fix TPZCreateApproximationSpace losing its family config on copy
- 4bc5ba7
<4bc5ba7>
Fix TPZAnalysis allowing a double free via shallow copy of fSolver
- cbaa0e7
<cbaa0e7>
Fix wrong index in TPZShapeHDivConstant's Fad<REAL> case
- dafdd35
<dafdd35>
Fix tautological guard in TPZH1ApproxCreator
- 5dbe3fb
<5dbe3fb>
Fix missing braces in TPZH1ApproxCreator::CreateAtomicMeshes
File Changes
(102 files <https://github.com/labmec/neopz/pull/215/files>)
- *M* Analysis/TPZAnalysis.h
<https://github.com/labmec/neopz/pull/215/files#diff-43f5e81391ad72a2d2bfe1db5f6bd743583fa7e6ce3983edcaad949e7d86cb7f>
(8)
- *M* Material/Elasticity/TPZMixedElasticityND.cpp
<https://github.com/labmec/neopz/pull/215/files#diff-00a6b64d6ed086c502806388d81e52367e88d7971dbd9d236ae7280d45df6e98>
(6)
- *M* Mesh/TPZCompElHDivDuplConnects.cpp
<https://github.com/labmec/neopz/pull/215/files#diff-60cbeeb0f885991b5defcb43c65bb0ba0777c0e802d132e290b7d27c4a42888c>
(2)
- *M* Mesh/TPZCompElHDivDuplConnectsBound.cpp
<https://github.com/labmec/neopz/pull/215/files#diff-8043676d925dbd7b6e62029d8ad791fd35875109547a80d27befb401a26a0a97>
(2)
- *M* Mesh/pzelchdiv.cpp
<https://github.com/labmec/neopz/pull/215/files#diff-b368f3a53619bb73f6762143ad4d6c05b2c8fccea88ff4744a2c650c7cb7beed>
(2)
- *M* Mesh/pzelchdivbound2.cpp
<https://github.com/labmec/neopz/pull/215/files#diff-fdb95d3e54037e7d70bf73273dc996da14831e98686018ec577614f0c0f6cbef>
(2)
- *M* Mesh/pzgmesh.cpp
<https://github.com/labmec/neopz/pull/215/files#diff-2205f42b296ece6727e983b3daea3230b724f9645f761d37d36e96f53e9646b8>
(3)
- *M* Post/pzpostprocanalysis.cpp
<https://github.com/labmec/neopz/pull/215/files#diff-37de7284a18d8cb00480ce4824c10dc0144d8a0476d08925df9edc0e84f15ed0>
(12)
- *M* Post/pzpostprocanalysis.h
<https://github.com/labmec/neopz/pull/215/files#diff-a3288d8685738629c5b1c6023681e16df2b3897a8ebdbd081a16e972c779a284>
(9)
- *M* Pre/TPZH1ApproxCreator.cpp
<https://github.com/labmec/neopz/pull/215/files#diff-bc91aa046638fd0d61118c9378ab41c7962e275bbd836c9b9b08f7a5ec5d61ef>
(7)
- *M* Pre/pzcreateapproxspace.h
<https://github.com/labmec/neopz/pull/215/files#diff-b5bfc009121edfae95a80c451c191a0d3b9a15289a819cc4354928e068e8590e>
(27)
- *M* README.md
<https://github.com/labmec/neopz/pull/215/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5>
(4)
- *M* Shape/TPZShapeHDiv.cpp
<https://github.com/labmec/neopz/pull/215/files#diff-15728e1ed948cdf39b4aa29fdaf39768594eea951f717aeaf121c347c2343298>
(2)
- *M* Shape/TPZShapeHDivConstant.cpp
<https://github.com/labmec/neopz/pull/215/files#diff-85f0bdeb66f64b46d2373a693e12e02bb8eb0eb57fd7599adfd35d00ea0778bb>
(4)
- *M* Shape/TPZShapeHDivConstantBound.cpp
<https://github.com/labmec/neopz/pull/215/files#diff-39201a8ee44cf762637e97b22de5811583c6afcaf8329fca5420d4d68cdaac50>
(2)
- *M* Shape/TPZShapeHDivOptimized.cpp
<https://github.com/labmec/neopz/pull/215/files#diff-6aa9d36e3662ba97530f67ddd4f71ce0ac2fdd05549e17891fa9edb7d671689f>
(2)
- *M* Topology/TPZTopologyUtils.h
<https://github.com/labmec/neopz/pull/215/files#diff-58e4cd4143063f33c202cf53abeb20c7dd19e193133a0c4608eee984bea33f1f>
(2)
- *A* ai-analysis/ALGORITHM_NOTES.md
<https://github.com/labmec/neopz/pull/215/files#diff-171bc1f28e7e9bbce09142289b0aa020b86f0b29f4355757eb017c8d6a575ad3>
(82)
- *A* ai-analysis/CODEBASE_ATLAS.md
<https://github.com/labmec/neopz/pull/215/files#diff-ed17ba316a4df866ee88554a736f045bdd3a06c5155c2b0c7ad44f96f75296bf>
(156)
- *A* ai-analysis/CPP_TECHNICAL_REVIEW.md
<https://github.com/labmec/neopz/pull/215/files#diff-c340ead76234645dd690661f393b36de7a2906dfac2d34c51745da20ead5c361>
(67)
- *A* ai-analysis/DOMAIN_PRIMER.md
<https://github.com/labmec/neopz/pull/215/files#diff-df756e740029d27df130719d01a3c8792064b1303abc5adc21e9b91b0f3d6788>
(83)
- *A* ai-analysis/EXECUTION_FLOWS.md
<https://github.com/labmec/neopz/pull/215/files#diff-455843666838dbace3b56be25030ed0f5b4724bac2880769657fb3963f8231a2>
(46)
- *A* ai-analysis/FINDINGS_AND_ROADMAP.md
<https://github.com/labmec/neopz/pull/215/files#diff-cc6e50da539be2637241ffe143706f491e66de8f57431c2caed452044f4aa423>
(64)
- *A* ai-analysis/NEOPZ_TECHNICAL_ASSESSMENT.md
<https://github.com/labmec/neopz/pull/215/files#diff-9e1a6c945606b6cb4c5d0164c2f1c67354574aa75490de33107fa96fa34342a9>
(92)
- *A* ai-analysis/TESTING_AND_VALIDATION_REVIEW.md
<https://github.com/labmec/neopz/pull/215/files#diff-5ac956ebeac579162b5a066b3be7e585a7b3a9a37d448848af58c04d1e63cc85>
(57)
- *A* ai-analysis/wiki/apps/app-error-estimation.md
<https://github.com/labmec/neopz/pull/215/files#diff-2443800fb25a73d4ad8c171dcacd9738cd6c1e8f78c17e31e010ed87a75bad13>
(31)
- *A* ai-analysis/wiki/apps/app-gfem.md
<https://github.com/labmec/neopz/pull/215/files#diff-0aa7fba799e65abec99f3c98cca443af01fb0329c37a88d073a32a24e879dcdf>
(32)
- *A* ai-analysis/wiki/apps/app-iterative-saddle-point.md
<https://github.com/labmec/neopz/pull/215/files#diff-bace747bf52840280e714bfa67e781ea9a88fa44e466f20220abafa1b3d79b1e>
(29)
- *A* ai-analysis/wiki/apps/app-mixed-elasticity.md
<https://github.com/labmec/neopz/pull/215/files#diff-d5643d1665f28ec1ff94204b714f369187d3cd834d80e1a7b597c96e067bb6dd>
(32)
- *A* ai-analysis/wiki/apps/app-wann.md
<https://github.com/labmec/neopz/pull/215/files#diff-184a29c327ed1b224bbc8661e225fd776a9324e0289b43ad8ddeeade174733d5>
(31)
- *A* ai-analysis/wiki/apps/apps-overview.md
<https://github.com/labmec/neopz/pull/215/files#diff-74e5358ac89c18fda9f26cae82eb2a5e5c0ff17842d20eacf4a655a651abecba>
(37)
- *A* ai-analysis/wiki/code/TPZAnalysis.md
<https://github.com/labmec/neopz/pull/215/files#diff-c7237874777d10199dd4f3ef07763b452f4c0d9a14a5cb957c8d7aba3a965316>
(36)
- *A* ai-analysis/wiki/code/TPZAutoPointer.md
<https://github.com/labmec/neopz/pull/215/files#diff-2d243e82a0d1dcb423b9e7807f10605e64b0249caf260e4ecaf057ed152cdbd0>
(28)
- *A* ai-analysis/wiki/code/TPZCompElHDiv.md
<https://github.com/labmec/neopz/pull/215/files#diff-9cd992f7899741e79dc925924527bfb9cff26118f9fab6b1b75bf2d3df563ef2>
(42)
- *A* ai-analysis/wiki/code/TPZCompMesh.md
<https://github.com/labmec/neopz/pull/215/files#diff-b0bba619b3915bf87dace7b88a2f210b89194216b4e5782a77b79a835b21b420>
(41)
- *A* ai-analysis/wiki/code/TPZConnect.md
<https://github.com/labmec/neopz/pull/215/files#diff-98c560da558510ca2eff14aab5a1b1f57ae7535c92589de15f3fc6141f2bc058>
(40)
- *A* ai-analysis/wiki/code/TPZGeoMesh.md
<https://github.com/labmec/neopz/pull/215/files#diff-624f923a8783f184033fc91472e071f93f914e47e4ec52a4ffbace07f32be32a>
(37)
- *A* ai-analysis/wiki/code/approx-space-creators.md
<https://github.com/labmec/neopz/pull/215/files#diff-a86da2fab32752e318d8ede091797df355b201653c0fd958c31f782f64e2f305>
(36)
- *A* ai-analysis/wiki/code/condensation-groups-submeshes.md
<https://github.com/labmec/neopz/pull/215/files#diff-eb7b71340e51860387e01005576b2d13f9037023b0e96282a3a2ee43cd799cd7>
(40)
- *A* ai-analysis/wiki/code/divfree-support-lib.md
<https://github.com/labmec/neopz/pull/215/files#diff-c7fa68e956a8558bf0cf5799930854f9fb1108ed170f647d4298bca8c7868f64>
(30)
- *A* ai-analysis/wiki/code/element-families.md
<https://github.com/labmec/neopz/pull/215/files#diff-8d28f49ab8078dffa5e1c2186123ac09633964ea06bf0fd23919cf1f8cc123aa>
(44)
- *A* ai-analysis/wiki/code/geometry-refinement-maps.md
<https://github.com/labmec/neopz/pull/215/files#diff-f75e468541322e4d7d89e06d4f03b9460cafd38c0d9134a8b32ecdff416ec722>
(43)
- *A* ai-analysis/wiki/code/material-system.md
<https://github.com/labmec/neopz/pull/215/files#diff-776530bce0e4d91e20f7d5c51b75bdc5aae7322efc5d056dac0944930b71742f>
(45)
- *A* ai-analysis/wiki/code/matrix-and-solvers.md
<https://github.com/labmec/neopz/pull/215/files#diff-c8f3034c16c1b8a93b952bda06c00360cc73d3ce2bb544f166dadcea85449388>
(43)
- *A* ai-analysis/wiki/code/mesh-io-generators.md
<https://github.com/labmec/neopz/pull/215/files#diff-adce80714e8ed2a48043c16dec5e185a62e04a1532b729f14ce65141a0badaff>
(31)
- *A* ai-analysis/wiki/code/multiphysics-composition.md
<https://github.com/labmec/neopz/pull/215/files#diff-f7ee02746947c2628e9e0370652bb389a55b04b8cd4a5dcbde97ba96e11b7e2a>
(36)
- *A* ai-analysis/wiki/code/persistence.md
<https://github.com/labmec/neopz/pull/215/files#diff-aa1956559fd5037965896966c4166d3869985e71051d020cfc11a313d63bdb61>
(27)
- *A* ai-analysis/wiki/code/post-processing-vtk.md
<https://github.com/labmec/neopz/pull/215/files#diff-32273939426e48cf45c1a784e8c3b74f747731412b9846653f3c97269f9bf618>
(31)
- *A* ai-analysis/wiki/code/shape-functions.md
<https://github.com/labmec/neopz/pull/215/files#diff-a956d29cf74f3999c0ce4a3e5a27c9d356429c95e0fbc6fe1e9983a05e26271c>
(35)
- *A* ai-analysis/wiki/code/structural-matrices.md
<https://github.com/labmec/neopz/pull/215/files#diff-4ac1bcee5b10d625051aa6551d93d3969045f5456dc6bb099819f11f20641e5f>
(39)
- *A* ai-analysis/wiki/code/topology-module.md
<https://github.com/labmec/neopz/pull/215/files#diff-cfbfb8da4c2e65e77698ee33de7e5f981bc68f915d4a253f795215e72fd1f779>
(32)
- *A* ai-analysis/wiki/concepts/assembly.md
<https://github.com/labmec/neopz/pull/215/files#diff-93abe736639021c9502e1d9b89a076d8c13fe9ad4690c972f61eb526b22a8fb4>
(22)
- *A* ai-analysis/wiki/concepts/de-rham-complex.md
<https://github.com/labmec/neopz/pull/215/files#diff-3a541fbeb03828f975383b4bb6c54a8b40283ac9ae4a0a092ab926b80d83d218>
(22)
- *A* ai-analysis/wiki/concepts/discontinuous-l2-dg.md
<https://github.com/labmec/neopz/pull/215/files#diff-62d29b157c1b0804f8748f46c4dced8817bd5ab7c927df36ef7ae7948b49a559>
(28)
- *A* ai-analysis/wiki/concepts/error-estimation-convergence.md
<https://github.com/labmec/neopz/pull/215/files#diff-73d72178acf6c9f30a1d0cdaf1d00ef7c9e9c822a4270fd09bfc403136557330>
(24)
- *A* ai-analysis/wiki/concepts/geometric-mappings.md
<https://github.com/labmec/neopz/pull/215/files#diff-879f55ae5b69d49635ab2368328b12e997c8e3b9d87b141c31534fb76a5c9a0a>
(24)
- *A* ai-analysis/wiki/concepts/h1-space.md
<https://github.com/labmec/neopz/pull/215/files#diff-0b99eb3dd3e514b5d64a706550b2b0379e95ad76853ddc2115d7601768c11cf0>
(26)
- *A* ai-analysis/wiki/concepts/hcurl-space.md
<https://github.com/labmec/neopz/pull/215/files#diff-68198ec25fd188f542bed140f098bf551e842b9d709caefd5bea1acd174f498d>
(26)
- *A* ai-analysis/wiki/concepts/hdiv-space.md
<https://github.com/labmec/neopz/pull/215/files#diff-14524bf8b882bd34e06677a3964d27fd18fdf7b507e8b5f040ce9332e76f9985>
(27)
- *A* ai-analysis/wiki/concepts/hp-adaptivity.md
<https://github.com/labmec/neopz/pull/215/files#diff-58b2142c478e4be96554c91778467c5cb09bb5a5f19279d9d60a7c034cc14eb7>
(25)
- *A* ai-analysis/wiki/concepts/hybridization.md
<https://github.com/labmec/neopz/pull/215/files#diff-7d72e11b3d944e60af8c9afd88c793ddf0d43be738697fb68bf92b92321d98fb>
(29)
- *A* ai-analysis/wiki/concepts/mhm.md
<https://github.com/labmec/neopz/pull/215/files#diff-2bd126fd80ee8dd4edf9f0569b1fb910fa1a5de3c1e5b17a1e2a267048ffdcab>
(23)
- *A* ai-analysis/wiki/concepts/mixed-methods.md
<https://github.com/labmec/neopz/pull/215/files#diff-4f36ecaec5f55898b86244a5358e27c28e001cf53717bf5994175b129dddc5c1>
(23)
- *A* ai-analysis/wiki/concepts/piola-transformations.md
<https://github.com/labmec/neopz/pull/215/files#diff-ea6b54344877acbbdbbbcf951ae0d9897ead716f3b9a5584552de89538d781ac>
(33)
- *A* ai-analysis/wiki/concepts/quadrature.md
<https://github.com/labmec/neopz/pull/215/files#diff-54d6b967afac0ed62ead92fbce2a5b8e668a93c18b898030e3aad86f0bf8f4ff>
(22)
- *A* ai-analysis/wiki/concepts/refinement-hanging-nodes.md
<https://github.com/labmec/neopz/pull/215/files#diff-d42533aacc67b5dcf8f686d9a916a26a72e653d5c81b28e10bf7d616be732a31>
(24)
- *A* ai-analysis/wiki/concepts/sbfem.md
<https://github.com/labmec/neopz/pull/215/files#diff-39581d3086e58f60a32342e53a0776b8b37e7a1d0f564d6136488a46fd8db9d0>
(24)
- *A* ai-analysis/wiki/concepts/static-condensation.md
<https://github.com/labmec/neopz/pull/215/files#diff-df853e3b00276cf76d7097ae8b9d357a187c4da9b1846a291e14f48df2c41892>
(23)
- *A* ai-analysis/wiki/concepts/vtk-output.md
<https://github.com/labmec/neopz/pull/215/files#diff-f338535aceca516b11c2b63d6215fcc419e332e5e4d63013fc04440766c6b1a1>
(23)
- *A* ai-analysis/wiki/devloo-1997-pz-environment.md
<https://github.com/labmec/neopz/pull/215/files#diff-2d73b7289ffebe81aae4d56b3b5c4c3d27d86db48856a40ee7d9668973341ce8>
(2)
- *A* ai-analysis/wiki/devloo-group-shape-construction.md
<https://github.com/labmec/neopz/pull/215/files#diff-1e533b020abb280d982a1aa679c2da017e946bd3f9c3f4be659b24092edff227>
(2)
- *A* ai-analysis/wiki/finding-debugstop-throws-release.md
<https://github.com/labmec/neopz/pull/215/files#diff-5af3ae513bb8eacb02361c0411ce620e095fac6d8495d2b3ddebb7190ae43051>
(2)
- *A* ai-analysis/wiki/findings/finding-approx-creator-hygiene.md
<https://github.com/labmec/neopz/pull/215/files#diff-6231dccfaa77f30dfb4374c8f6c9ebee1a324eacc38a759d9beb09fec93365b1>
(38)
- *A*
ai-analysis/wiki/findings/finding-approxspace-copy-drops-families.md
<https://github.com/labmec/neopz/pull/215/files#diff-882575fdd565f03ae6fff718a701252196ad206f1e98b1683825f36aa54b0f2d>
(33)
- *A* ai-analysis/wiki/findings/finding-build-config-gaps.md
<https://github.com/labmec/neopz/pull/215/files#diff-a27f4b14a6e5c38311ec7d897c23a6f4c7c2438b27244ddec73e99b6677b8990>
(29)
- *A* ai-analysis/wiki/findings/finding-debugstop-throws-release.md
<https://github.com/labmec/neopz/pull/215/files#diff-19230dcad4d20b353160f1b77736d4365809afa3e6678637d485865ce104e9a6>
(32)
- *A* ai-analysis/wiki/findings/finding-global-state-cluster.md
<https://github.com/labmec/neopz/pull/215/files#diff-d8690361c73e8fe1cee6be614bd880cc0614a69553319de1a1b25f0ac9599626>
(33)
- *A* ai-analysis/wiki/findings/finding-hdivconstant-fad-index.md
<https://github.com/labmec/neopz/pull/215/files#diff-6feefcc2d6c2879252d0d8b30e772adea39ade33e05a2f3101d83fe637902422>
(30)
- *A*
ai-analysis/wiki/findings/finding-hybridelasticity2d-missing-rhs-at-pin.md
<https://github.com/labmec/neopz/pull/215/files#diff-799287feb6c5216c4dd8da2c7e09743b79612d825bc23d59f0967a97d3c3eb71>
(32)
- *A*
ai-analysis/wiki/findings/finding-local-test-crashes-workingtree.md
<https://github.com/labmec/neopz/pull/215/files#diff-e13111e5fe0b8959f93d2280da4a9d21b124e28b209d2d06dec7310b02e13137>
(33)
- *A* ai-analysis/wiki/findings/finding-matred-solver-mode-mislabel.md
<https://github.com/labmec/neopz/pull/215/files#diff-5e9d55c4f7338c9e56c4f703d65892f28cc3621518ac45a3d9466e3c943744eb>
(32)
- *A* ai-analysis/wiki/findings/finding-mesh-lifetime-ownership.md
<https://github.com/labmec/neopz/pull/215/files#diff-fc2fded7d24cf2fbe4ae9f7c73a0ef33ff861aaa1b8c7dc271f3fedb84bb0630>
(34)
- *A* ai-analysis/wiki/findings/finding-mhm-target-uncompilable.md
<https://github.com/labmec/neopz/pull/215/files#diff-190efa0adaad703cdaa2801c1848e1492fe410b0645829daf2ae3a64883b7c17>
(31)
- *A* ai-analysis/wiki/findings/finding-rusage-memory-units.md
<https://github.com/labmec/neopz/pull/215/files#diff-9ceb4b377d748e13b4d76d422dfd38bc56cf90d719886131beaa55fc13de86d1>
(30)
- *A* ai-analysis/wiki/findings/finding-thread-shared-materials.md
<https://github.com/labmec/neopz/pull/215/files#diff-3c1cf696d4f0eae3df9fe5693718ff6fa0b55f3740c06ac8930dcac2b6226f9c>
(31)
- *A* ai-analysis/wiki/findings/finding-voronoi-null-ganalytic.md
<https://github.com/labmec/neopz/pull/215/files#diff-66ca2e5eeca7e2ecb3176346f738c26d9ac96855fe1fa446aeb9000974030840>
(27)
- *A* ai-analysis/wiki/flows/flow-dfreebubbles-1el.md
<https://github.com/labmec/neopz/pull/215/files#diff-fd279bfbf5c527f395bd4dbd592a93ed5b4981154a4a59420ab51e62068c310f>
(39)
- *A* ai-analysis/wiki/flows/flow-dupl-connects.md
<https://github.com/labmec/neopz/pull/215/files#diff-746fcc22a72c1efd546b00c488123c447371d0c52a12f23da8d9ef06490bd93b>
(30)
- *A* ai-analysis/wiki/flows/flow-iter-elast.md
<https://github.com/labmec/neopz/pull/215/files#diff-301ba3de2a6fe6cd2a41817ffbd4bcf9f7756cac74b9f12a539f36dc122e98ba>
(45)
- *A* ai-analysis/wiki/flows/flow-mhm-hdivconstant.md
<https://github.com/labmec/neopz/pull/215/files#diff-acdf4193cb208022a6cc987424356e25073fa937fde201faeb03a44d0c0dbdd5>
(32)
- *A* ai-analysis/wiki/flows/flow-unit-test-hdiv-creator.md
<https://github.com/labmec/neopz/pull/215/files#diff-2078e7bd48defd4a691f65d72bfded7c8239cfa7f19add89fd17772983c67457>
(34)
- *A* ai-analysis/wiki/index.md
<https://github.com/labmec/neopz/pull/215/files#diff-f6061a7497520b5fa3fcfa4b56d29e7743673344f2baf9132ef2a254fcf6b156>
(115)
- *A* ai-analysis/wiki/log.md
<https://github.com/labmec/neopz/pull/215/files#diff-c57f73b1be5d2bb9a86f309d7e0a73cc6f7239937e836001ed57a594bc5bd5cf>
(134)
- *A* ai-analysis/wiki/sources/araya-2013-mhm.md
<https://github.com/labmec/neopz/pull/215/files#diff-0bf42cd5c2833d43f7d32a4db184356b6d31ac24da9808fa51b355759383f682>
(35)
- *A*
ai-analysis/wiki/sources/avancini-2025-double-hybrid-elasticity.md
<https://github.com/labmec/neopz/pull/215/files#diff-a80019971a75eb66ed3c615a2a5931577319edfc1557fd3730ce87e7e93e8985>
(39)
- *A* ai-analysis/wiki/sources/boffi-brezzi-fortin-2013.md
<https://github.com/labmec/neopz/pull/215/files#diff-245302da42d2c65d95815ab975c2a5eaa7d954734abeee14553b72b97d65712c>
(38)
- *A* ai-analysis/wiki/sources/carvalho-2024-semi-hybrid-stokes.md
<https://github.com/labmec/neopz/pull/215/files#diff-e396d579a12c561bc4c5fa5a2c81e64ea38de592f3e0fb983ca0063e20525806>
(38)
- *A* ai-analysis/wiki/sources/cockburn-2009-unified-hybridization.md
<https://github.com/labmec/neopz/pull/215/files#diff-4ee639c76c3231974d749e7b80aa011df860a7ac657fabf38cde7d49d6e3994f>
(36)
- *A* ai-analysis/wiki/sources/devloo-1997-pz-environment.md
<https://github.com/labmec/neopz/pull/215/files#diff-a9fd1939e4c7063d93de93f7e2dd7b11ea9f6fb37c273962ccead871204f5d87>
(38)
- *A* ai-analysis/wiki/sources/devloo-group-shape-construction.md
<https://github.com/labmec/neopz/pull/215/files#diff-3faa8247f29a88dffa5dae5bae4d7f4e6b39ebcd4503d59b0de39bf4ccf3fe62>
(40)
- *A* ai-analysis/wiki/sources/devloo-hdiv-variants-accuracy.md
<https://github.com/labmec/neopz/pull/215/files#diff-8ab6e99bf4b5b74539a5f48d957db81ce5a2389701465830ce2947cf8a64db13>
(36)
- *A* ai-analysis/wiki/sources/devloo-mhm-elasticity-polygonal.md
<https://github.com/labmec/neopz/pull/215/files#diff-5e64a22cd1ce3a952815add28cd07f6c581f96ab94352764fbe151eee2ab7091>
(36)
Patch Links:
- https://github.com/labmec/neopz/pull/215.patch
- https://github.com/labmec/neopz/pull/215.diff
—
Reply to this email directly, view it on GitHub
<#215?email_source=notifications&email_token=ACZ36ZC57VYDDZAE266V3S35G5WABA5CNFSNUABEM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UF42DCNBTGU4TKMZWGSTHEZLBONXW5KTTOVRHGY3SNFRGKZFFMV3GK3TUVRTG633UMVZF6Y3MNFRWW>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACZ36ZEKHDKTJ6TEVQYURE35G5WABAVCNFSNUABEKJSXA33TNF2G64TZHMZTGMZUGE4TAMB3JFZXG5LFHM2DSOBZGM2TQNZUGWQXMAQ>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/ACZ36ZATSS7PSS4F77COBED5G5WABA5CNFSNUABEM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UF42DCNBTGU4TKMZWGSTHEZLBONXW5KTTOVRHGY3SNFRGKZFFMV3GK3TUVJTG633UMVZF62LPOM>
and Android
<https://github.com/notifications/mobile/android/ACZ36ZAB2B6E5X54NJ4NZM35G5WABA5CNFSNUABEM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UF42DCNBTGU4TKMZWGSTHEZLBONXW5KTTOVRHGY3SNFRGKZFFMV3GK3TUVZTG633UMVZF6YLOMRZG62LE>.
Download it today!
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
***@***.***
|
|
I did a really small test: main.cpp: wgma/util.cpp: And I have obtained the same values: But I confess that I do not know if this test was enough. |
|
I think the test doesn't catch it because both prints call The bug becomes visible when
To reproduce the problem, change the print in pztopology::GetTolerance()to a direct access: pztopology::gToleranceSince It would also be useful to add unit tests covering this problem and the behavior reported in issue 6. |
|
Yes, you are correct, I have verified it.
Given that we do have the setters and getters for the tolerance, wouldn't
it make more sense to remove gTolerance from the header file?
Em ter., 28 de jul. de 2026 às 15:17, pereiraalessandra <
***@***.***> escreveu:
… *pereiraalessandra* left a comment (labmec/neopz#215)
<#215 (comment)>
@orlandini <https://github.com/orlandini>
I think the test doesn't catch it because both prints call GetTolerance().
This function has only one definition, in TPZTopologyUtils.cpp, so every
call reads the same instance of gTolerance, regardless of which source
file calls it.
The bug becomes visible when gTolerance is accessed directly from a
source file other than TPZTopologyUtils.cpp, without going through
GetTolerance(). One example already in the codebase:
- Topology/tpzprism.cpp:990: double zero = pztopology::gTolerance;,
inside TPZPrism::CheckProjectionForSingularity.
To reproduce the problem, change the print in wgma/util.cpp from
pztopology::GetTolerance()
to a direct access:
pztopology::gTolerance
Since wgma/util.cpp and TPZTopologyUtils.cpp are compiled separately, the
print in wgma/util.cpp should then show the default value instead of 0.01.
It would also be useful to add unit tests covering this problem and the
behavior reported in issue 6.
—
Reply to this email directly, view it on GitHub
<#215?email_source=notifications&email_token=AC2GJDTYFSISR7NEKSOWY535HCRV7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJQGQ3DGNRQGUY2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-5104636051>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC2GJDUNIOECQBAJTAP42FD5HCRV7AVCNFSNUABEKJSXA33TNF2G64TZHMZTGMZUGE4TAMB3JFZXG5LFHM2DSOBZGM2TQNZUGWQXMAQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Francisco Orlandini
|
Fix verified issues
Summary
This PR fixes eight issues identified by an AI-assisted code analysis.
For each issue, the sections below describe:
1.
SetTolerance()updated only one source file's copy of the variableFile:
Topology/TPZTopologyUtils.hProblem
gTolerancewas defined as a namespace-scopestaticvariable inside a header:At namespace scope,
staticgives the variable internal linkage. Consequently, every.cppfile that includes the header gets its own independent copy ofgTolerance, instead of all of them sharing one.SetTolerance()is implemented inTPZTopologyUtils.cpp, so it only ever modified the copy that lives in that one.cppfile. Other users ofgTolerance, including its use as the default tolerance inIsInParametricDomain(), are defined in different.cppfiles and kept reading their own unchanged copies.As a result, calls to
SetTolerance()were silently ignored by most of the library.Fix
Changed the definition to a C++17 inline variable:
An inline variable may be defined in a header while still representing a single object shared by every
.cppfile that includes it, instead of one copy per file.2. Destroying a geometric mesh first left the computational mesh with a dangling pointer
File:
Mesh/pzgmesh.cppFunction:
TPZGeoMesh::~TPZGeoMesh()Problem
TPZCompMeshandTPZGeoMeshmaintain references to each other.When a computational mesh is destroyed first,
TPZCompMesh::~TPZCompMesh()already notifies the associated geometric mesh by callingResetReference().The reverse case was not handled.
TPZGeoMesh::~TPZGeoMesh()calledCleanUp()without clearing the corresponding reference stored by the computational mesh.If a geometric mesh was destroyed while an associated computational mesh was still alive, the computational mesh retained a pointer to freed memory. A subsequent access such as
TPZCompEl::Reference()could eventually dereference the deleted geometric mesh through:
This resulted in undefined behavior.
Fix
Added the corresponding notification in
TPZGeoMesh::~TPZGeoMesh():3. Debug checks used the wrong preprocessor macro
Files:
Shape/TPZShapeHDivConstant.cppShape/TPZShapeHDivOptimized.cppShape/TPZShapeHDiv.cppShape/TPZShapeHDivConstantBound.cppMesh/pzelchdiv.cppMesh/pzelchdivbound2.cppMesh/TPZCompElHDivDuplConnects.cppMesh/TPZCompElHDivDuplConnectsBound.cppMaterial/Elasticity/TPZMixedElasticityND.cppProblem
The project uses
PZDEBUGas its debug-build macro, but 11 consistency and bounds-checking blocks across these files used:#ifdef DEBUGSince
DEBUGis not defined by the project build configuration, these blocks were never compiled, including in Debug builds.Fix
Replaced all 11 occurrences with:
#ifdef PZDEBUG4.
TPZCreateApproximationSpacedid not preserve its configured approximation families when copiedFile:
Pre/pzcreateapproxspace.hProblem
The manually implemented copy constructor and assignment operator did not copy the following members:
fhdivfam fh1fam fhcurlfam fStyleThese members record the configured approximation-space families and style.
TPZCompMeshcontains aTPZCreateApproximationSpaceobject and exposes mesh cloning throughClone(). Therefore, cloning a mesh configured with a non-default family, such asEHDivConstant, could produce an object whose stored configuration reported the default family even though its shape-function creation callbacks still reflected the original configuration.This left the copied object in an internally inconsistent state.
Fix
Replaced the hand-written copy operations with compiler-generated ones:
All members already have valid copy semantics. Using
= defaultalso prevents future data members from being accidentally omitted from the copy operations.Also cleaned up three setters in the same header that had
constas part of avoidreturn type, e.g.:changed to:
consthas no effect on avoidreturn type. This does not change how these methods behave or are called.5.
TPZAnalysiscould be shallow-copied, causing double deletion offSolverFiles:
Analysis/TPZAnalysis.hPost/pzpostprocanalysis.hPost/pzpostprocanalysis.cppProblem
TPZAnalysisownsfSolver: it deletes it during cleanup and in its destructor. But the class did not declare a copy constructor oroperator=, so the compiler generated its own. For a raw pointer member, that means copying the address, not the object it points to:a1anda2are now two separate objects whosefSolverpoints to the sameTPZSolver. Each one still believes it owns that solver and willdeleteit when destroyed. The one that is destroyed second ends up callingdeleteon memory that the first one already freed (double free).TPZPostProcAnalysis(a subclass ofTPZAnalysis) also explicitly wrote its own copy constructor andoperator=, instead of just inheriting the unsafe compiler-generated ones:The copy constructor calls
TPZLinearAnalysis(copy), which copies the base classTPZAnalysisand inherits the same double-free problem. Theoperator=does not copy anything fromcopyat all (it just resets the current object and ignores its argument).Fix
Both classes now explicitly forbid copying, instead of allowing an unsafe copy or hand-writing a broken one:
= deletetells the compiler to reject any attempt to copy one of these objects.No code in the current repository copies a
TPZAnalysisor aTPZPostProcAnalysis, so this change does not affect any existing behavior. It only removes an operation that was never safe to use.6. Wrong face index in the
Fad<REAL>branch ofTPZShapeHDivConstantFile:
Shape/TPZShapeHDivConstant.cppProblem
The
Fad<REAL>overload ofTPZShapeHDivConstant::Shape()used:inside a loop over the element facets.
Because the index did not include the current facet index
i, every facet used the kernel-function count associated with the first facet.The corresponding
REALoverload already used the correct expression:This can misalign the function blocks and lead to incorrect shape functions, incorrect automatic derivatives, or out-of-bounds matrix accesses.
Fix
Changed:
to:
The
Fad<REAL>branch now matches the indexing already used by theREALbranch.7. Tautological condition in
TPZH1ApproxCreator::CreateBoundaryHDivSpace()File:
Pre/TPZH1ApproxCreator.cppProblem
The function contained the following condition:
This expression is always true.
For any possible value of
fHybridType, it must be different from at least one of the two enum values. Consequently, the correspondingelsebranch containingDebugStop()was unreachable.Fix
Changed the comparisons from
!=to==while preserving||:With the current call flow,
fHybridTypecan only beEStandardorEStandardSquaredwhen execution reaches this function.CheckSetupConsistency()already rejectsESemi, andCreateAtomicMeshes()rejectsENone.Therefore, this change does not alter the behavior of any currently valid execution path. It only serves as a defensive check, ensuring that any future unsupported or unhandled enum value is detected instead of being silently treated as valid.
8. Missing braces made the control flow in
CreateAtomicMeshes()misleading and fragileFile:
Pre/TPZH1ApproxCreator.cppProblem
The function contained:
if (HybridType() != HybridizationType::ENone) meshvec[countMesh++] = CreateBoundaryHDivSpace(); meshvec[countMesh++] = CreateL2Space();In C++, an
ifstatement without braces controls only the immediately following statement.Therefore, despite the indentation, the code was interpreted as:
The current behavior is valid because
ENoneis rejected earlier in the function. However, the misleading indentation made the intended control flow unclear and left the code dependent on that earlier validation remaining unchanged.Fix
Added braces around the statement that is actually conditional:
This change clarifies the actual behavior without changing it.