@@ -62,7 +62,7 @@ NestedIterationSolver(SmartPtr<ILinearOperatorInverse<vector_type> > LinearSolve
6262 m_spAss (NULL ),
6363 m_dgbCall (0 ),
6464 m_lastNumSteps (0 ),
65- m_bUseAdaptiveRefinement (true )
65+ m_bUseAdaptiveRefinement (true ), m_TOL( 1e-3 ), m_absTOL( 1e-12 ), m_maxSteps( 100 )
6666{};
6767
6868template <typename TDomain, typename TAlgebra>
@@ -74,7 +74,8 @@ NestedIterationSolver() :
7474 m_spAss (NULL ),
7575 m_dgbCall (0 ),
7676 m_lastNumSteps (0 ),
77- m_bUseAdaptiveRefinement (true )
77+ m_bUseAdaptiveRefinement (true ),
78+ m_TOL (1e-3 ), m_absTOL(1e-12 ), m_maxSteps(100 )
7879{};
7980
8081template <typename TDomain, typename TAlgebra>
@@ -86,7 +87,7 @@ NestedIterationSolver(SmartPtr<IOperator<vector_type> > N) :
8687 m_spAss (NULL ),
8788 m_dgbCall (0 ),
8889 m_lastNumSteps (0 ),
89- m_bUseAdaptiveRefinement (true )
90+ m_bUseAdaptiveRefinement (true ), m_TOL( 1e-3 ), m_absTOL( 1e-12 ), m_maxSteps( 100 )
9091{
9192 init (N);
9293};
@@ -102,7 +103,7 @@ NestedIterationSolver(SmartPtr<IAssemble<TAlgebra> > spAss) :
102103 m_dgbCall (0 ),
103104 m_lastNumSteps (0 ),
104105 m_baseLevel (0 ),
105- m_bUseAdaptiveRefinement (true )
106+ m_bUseAdaptiveRefinement (true ), m_TOL( 1e-3 ), m_absTOL( 1e-12 ), m_maxSteps( 100 )
106107{
107108 m_N = SmartPtr<AssembledOperator<TAlgebra> >(new AssembledOperator<TAlgebra>(m_spAss));
108109};
@@ -150,12 +151,12 @@ bool NestedIterationSolver<TDomain,TAlgebra>::prepare(vector_type& u)
150151// ! Refines domain and provides error estimate.
151152/* ! Values depend on m_spDomErr */
152153template <typename TDomain, typename TAlgebra>
153- number NestedIterationSolver<TDomain,TAlgebra>::refine_domain (const grid_function_type& u)
154+ void NestedIterationSolver<TDomain,TAlgebra>::estimate_and_mark_domain (const grid_function_type& u, SmartPtr<IElementMarkingStrategy<TDomain> > spMarking, bool bClearMarks )
154155{
155156 UG_LOG (" Computing error... " << std::endl);
156157
157158 typedef DomainDiscretization<TDomain, TAlgebra> domain_disc_type;
158- // typedef IDomainErrorIndicator<TAlgebra> domain_indicator_type;
159+ // typedef IDomainErrorIndicator<TAlgebra> domain_indicator_type;
159160
160161 SmartPtr<domain_disc_type> spDomainEstimator = m_spDomErr.template cast_dynamic <domain_disc_type>();
161162
@@ -165,19 +166,21 @@ number NestedIterationSolver<TDomain,TAlgebra>::refine_domain(const grid_functio
165166
166167 // compute error
167168 if (m_spElemError.valid ()) {
169+ // debug version
168170 spDomainEstimator->calc_error (u, u.dd (), &(*m_spElemError));
169171 } else {
172+ // standard version
170173 spDomainEstimator->calc_error (u, u.dd ());
171174 }
175+
172176 // set (new) marks
173- m_spRefiner->clear_marks ();
174- spDomainEstimator->mark_with_strategy (*m_spRefiner, m_spRefinementMarking);
175- UG_LOG (" Estimated error: " << m_spRefinementMarking->global_estimated_error ());
177+ if (bClearMarks) m_spRefiner->clear_marks ();
178+ spDomainEstimator->mark_with_strategy (*m_spRefiner, spMarking);
179+ UG_LOG (" Estimated error: " << spMarking->global_estimated_error ());
180+
181+
176182
177- const number err = m_spRefinementMarking->global_estimated_error ();
178- if (err >= m_TOL) {m_spRefiner->refine ();}
179183
180- return err;
181184}
182185
183186
@@ -286,14 +289,14 @@ bool NestedIterationSolver<TDomain,TAlgebra>::apply(vector_type& u)
286289
287290 // Solve linearized system.
288291 try {
289- NESTED_ITER_PROFILE_BEGIN (NewtonApplyLinSolver);
290- if (!m_spLinearSolver->apply (u, *spD))
291- {
292- UG_LOG (" ERROR in 'NestedIterationSolver::apply': Cannot apply Inverse Linear "
293- " Operator for Jacobi-Operator.\n " );
294- return false ;
295- }
296- NESTED_ITER_PROFILE_END ();
292+ NESTED_ITER_PROFILE_BEGIN (NewtonApplyLinSolver);
293+ if (!m_spLinearSolver->apply (u, *spD))
294+ {
295+ UG_LOG (" ERROR in 'NestedIterationSolver::apply': Cannot apply Inverse Linear "
296+ " Operator for Jacobi-Operator.\n " );
297+ return false ;
298+ }
299+ NESTED_ITER_PROFILE_END ();
297300 }UG_CATCH_THROW (" NestedIterationSolver::apply: Application of Linear Solver failed." );
298301
299302 // Adjust solution.
@@ -315,25 +318,34 @@ bool NestedIterationSolver<TDomain,TAlgebra>::apply(vector_type& u)
315318 break ;
316319 }
317320
318- // Refine domain and check error .
319- number err = this ->refine_domain (usol);
321+ // Estimate and mark domain .
322+ this ->estimate_and_mark_domain (usol, m_spRefinementMarking );
320323
321- if (m_spElemError. valid ())
322- {
323- // write defect for debug
324- std::string name (" NESTED_ITER_Error" );
325- name.append (ext);
326- VTKOutput<TDomain::dim> outError;
327- outError.print (name.c_str (), *m_spElemError);
324+ // OPTIONAL: write defect for debug
325+ if (m_spElemError. valid ())
326+ {
327+ std::string name (" NESTED_ITER_Error" );
328+ name.append (ext);
329+ VTKOutput<TDomain::dim> outError;
330+ outError.print (name.c_str (), *m_spElemError);
328331 }
329332
333+ // Check error.
334+ const number err = m_spRefinementMarking->global_estimated_error ();
335+ double desiredTOL = (m_spAssociatedSpace.valid ()) ? m_TOL*m_spAssociatedSpace->norm (usol) + m_absTOL : m_TOL;
336+
337+ UG_LOG (" NI *** Desired tolerance: " << m_TOL << " * " << m_spAssociatedSpace->norm (usol) << " + " << m_absTOL <<std::endl);
338+
330339 // Quit or continue?
331- if (err < m_TOL )
340+ if (err < desiredTOL )
332341 {
333- UG_LOG (" SUCCESS: Error smaller than tolerance: " << err << " < " << m_TOL << std::endl);
342+ // Quit.
343+ UG_LOG (" SUCCESS: Error smaller than tolerance: " << err << " < " << desiredTOL << std::endl);
334344 break ;
335345 } else {
336- UG_LOG (" FAILED: Error (still) greater than tolerance: " << err << " > " << m_TOL << std::endl);
346+ // Refine and continue.
347+ UG_LOG (" FAILED: Error (still) greater than tolerance: " << err << " > " << desiredTOL << std::endl);
348+ m_spRefiner->refine ();
337349 }
338350 }
339351
0 commit comments