Skip to content

Commit 7fda4c2

Browse files
committed
minor safety changes in IMultigridElementIndicators
1 parent 76a6ad4 commit 7fda4c2

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

ugbase/lib_disc/function_spaces/error_elem_marking_strategy.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,29 @@ class IMultigridElementIndicators
6363
/// CTOR
6464
IMultigridElementIndicators() {}
6565

66+
/// DTOR
67+
~IMultigridElementIndicators()
68+
{
69+
detach_indicators();
70+
}
71+
6672
/// Attach error indicator to multigrid
6773
void attach_indicators(SmartPtr<MultiGrid> pMG)
6874
{
6975
typedef typename domain_traits<dim>::element_type elem_type;
7076

71-
pMG->template attach_to_dv<elem_type>(m_aError, -1.0); // attach with default value
77+
if (!m_pMG->has_attachment<elem_type>(m_aError))
78+
pMG->template attach_to_dv<elem_type>(m_aError, -1.0); // attach with default value
7279
m_pMG = pMG;
7380
m_aaError = attachment_accessor_type(*m_pMG, m_aError);
7481
}
7582

7683
/// Detach error indicator from multigrid
7784
void detach_indicators()
78-
{ m_pMG->template detach_from<elem_type>(m_aError); }
85+
{
86+
if (m_pMG->has_attachment<elem_type>(m_aError))
87+
m_pMG->template detach_from<elem_type>(m_aError);
88+
}
7989

8090

8191
/// returns error indicator value
@@ -91,6 +101,7 @@ class IMultigridElementIndicators
91101

92102

93103
/// TODO: remove this function
104+
/// (mbreit: no, please leave it, it is very useful, at least with const access)
94105
attachment_accessor_type& errors()
95106
{ return m_aaError; }
96107

0 commit comments

Comments
 (0)