Skip to content

Commit cf0ab34

Browse files
roystgnrjwpeterson
authored andcommitted
Avoid clear() in DiffSystem class destructors
The previous code doesn't do what it might be expected to do. Since the methods called by clear are virtual, and any subclasses have been partially-destructed down to the base class at this point, and the base class implementations of physics and qoi clearing are no-ops, calling those functions does nothing. If clearing of subclass data needs to be done then it needs to be done in the subclasses' destructor. On Intel 16 in opt mode, those virtual function calls give me a segfault, which I'm pretty sure is a compiler bug, but since fixing my stupid code also avoids the segfault I'm not complaining too hard.
1 parent 90496b0 commit cf0ab34

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

include/systems/fem_system.h

-6
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ class FEMSystem : public DifferentiableSystem,
7777
*/
7878
typedef DifferentiableSystem Parent;
7979

80-
/**
81-
* Clear all the data structures associated with
82-
* the system.
83-
*/
84-
virtual void clear () libmesh_override;
85-
8680
/**
8781
* Prepares \p matrix or \p rhs for matrix assembly.
8882
* Users may reimplement this to add pre- or post-assembly

src/systems/diff_system.C

+7-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ DifferentiableSystem::DifferentiableSystem
5050

5151
DifferentiableSystem::~DifferentiableSystem ()
5252
{
53-
this->clear();
53+
// If we had an attached Physics object, delete it.
54+
if (this->_diff_physics != this)
55+
delete this->_diff_physics;
56+
57+
// If we had an attached QoI object, delete it.
58+
if (this->diff_qoi != this)
59+
delete this->diff_qoi;
5460
}
5561

5662

src/systems/fem_system.C

-8
Original file line numberDiff line numberDiff line change
@@ -830,14 +830,6 @@ FEMSystem::FEMSystem (EquationSystems& es,
830830

831831
FEMSystem::~FEMSystem ()
832832
{
833-
this->clear();
834-
}
835-
836-
837-
838-
void FEMSystem::clear()
839-
{
840-
Parent::clear();
841833
}
842834

843835

0 commit comments

Comments
 (0)