38 #ifndef __H__UG__LIB_DISC__OPERATOR__NON_LINEAR_OPERATOR__NL_JACOBI__NL_JACOBIL_IMPL_H_
39 #define __H__UG__LIB_DISC__OPERATOR__NON_LINEAR_OPERATOR__NL_JACOBI__NL_JACOBIL_IMPL_H_
48 #define PROFILE_NL_JACOBI
49 #ifdef PROFILE_NL_JACOBI
50 #define NL_JACOBI_PROFILE_FUNC() PROFILE_FUNC_GROUP("NL Jacobi")
51 #define NL_JACOBI_PROFILE_BEGIN(name) PROFILE_BEGIN_GROUP(name, "NL Jacobi")
52 #define NL_JACOBI_PROFILE_END() PROFILE_END()
54 #define NL_JACOBI_PROFILE_FUNC()
55 #define NL_JACOBI_PROFILE_BEGIN(name)
56 #define NL_JACOBI_PROFILE_END()
61 template <
typename TAlgebra>
64 m_spConvCheck(spConvCheck),
69 template <
typename TAlgebra>
77 template <
typename TAlgebra>
81 m_spConvCheck = spConvCheck;
82 m_spConvCheck->set_offset(3);
83 m_spConvCheck->set_symbol(
'#');
84 m_spConvCheck->set_name(
"Nonlinear Jacobi Solver");
87 template <
typename TAlgebra>
93 m_spAssOp = op.template cast_dynamic<AssembledOperator<TAlgebra> >();
94 if(m_spAssOp.invalid())
95 UG_THROW(
"NLJacobiSolver: currently only works for AssembledDiscreteOperator.");
97 m_spAss = m_spAssOp->discretization();
99 UG_THROW(
"AssembledLinearOperator: Assembling routine not set.");
104 template <
typename TAlgebra>
111 template <
typename TAlgebra>
119 if(m_spJ.invalid() || m_spJ->discretization() != m_spAss) {
121 m_spJ->set_level(m_spAssOp->level());
130 m_spAssOp->prepare(u);
132 UG_CATCH_THROW(
"NLJacobiSolver::apply: Prepare of Operator failed.");
137 m_spAssOp->apply(*spD, u);
140 "Computation of Start-Defect failed.");
144 char ext[20]; snprintf(ext,
sizeof(ext),
"_iter%03d", loopCnt);
145 std::string
name(
"NLJacobi_Defect");
147 write_debug(*spD,
name.c_str());
148 write_debug(u,
"NLJacobi_StartSolution");
151 m_spConvCheck->start(*spD);
156 while(!m_spConvCheck->iteration_ended())
169 "Initialization of Jacobian failed.");
172 std::string matname(
"NLJacobi_Jacobian");
174 write_debug(m_spJ->get_matrix(), matname.c_str());
179 for (
size_t i = 0; i < u.size(); i++)
192 m_spAssOp->prepare(u);
193 m_spAssOp->apply(*spD, u);
198 snprintf(ext,
sizeof(ext),
"_iter%03d", loopCnt);
201 m_spConvCheck->update(*spD);
204 std::string
name(
"NLJacobi_Defect");
name.append(ext);
205 write_debug(*spD,
name.c_str());
208 return m_spConvCheck->post();
211 template <
typename TAlgebra>
215 std::string
name(filename);
216 char ext[20]; snprintf(ext,
sizeof(ext),
"_call%03d", m_dgbCall);
217 name.append(ext).append(
".vec");
220 base_writer_type::write_debug(vec,
name.c_str());
223 template <
typename TAlgebra>
227 std::string
name(filename);
228 char ext[20]; snprintf(ext,
sizeof(ext),
"_call%03d", m_dgbCall);
229 name.append(ext).append(
".mat");
232 base_writer_type::write_debug(mat,
name.c_str());
location name
Definition: checkpoint_util.lua:128
Definition: smart_pointer.h:108
matrix operator based on the assembling of a problem
Definition: assembled_linear_operator.h:60
TAlgebra::vector_type vector_type
type of vector
Definition: debug_writer.h:360
TAlgebra::matrix_type matrix_type
type of matrix
Definition: debug_writer.h:363
Definition: convergence_check.h:72
describes a mapping X->Y
Definition: operator.h:86
virtual bool apply(vector_type &u)
apply Operator, i.e. op^{-1}(0) = u
Definition: nl_jacobi_impl.h:112
NLJacobiSolver()
default constructor
Definition: nl_jacobi_impl.h:71
void write_debug(const vector_type &vec, const char *filename)
Definition: nl_jacobi_impl.h:212
virtual bool init(SmartPtr< IOperator< vector_type > > op)
This operator inverts the Operator op: Y -> X.
Definition: nl_jacobi_impl.h:90
void set_convergence_check(SmartPtr< IConvergenceCheck< vector_type > > spConvCheck)
Definition: nl_jacobi_impl.h:79
virtual bool prepare(vector_type &u)
prepare Operator
Definition: nl_jacobi_impl.h:105
Definition: convergence_check.h:179
#define UG_CATCH_THROW(msg)
Definition: error.h:64
#define UG_THROW(msg)
Definition: error.h:57
bool InverseMatMult(number &dest, const double &beta, const TMat &mat, const TVec &vec)
you can implement this function with GetInverse and MatMult
#define NL_JACOBI_PROFILE_BEGIN(name)
Definition: nl_jacobi_impl.h:51
#define NL_JACOBI_PROFILE_END()
Definition: nl_jacobi_impl.h:52
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition: smart_pointer.h:836
function ProblemDisc new(problemDesc, dom)