80 #ifdef USE_UMFPACK_LONG
82 #define UMFPACKWRAP_defaults umfpack_dl_defaults
83 #define UMFPACKWRAP_free_symbolic umfpack_dl_free_symbolic
84 #define UMFPACKWRAP_free_numeric umfpack_dl_free_numeric
86 #define UMFPACKWRAP_symbolic(size, app, aip, axp, sym, ctrl, info) \
87 umfpack_dl_symbolic(size, size, app, aip, axp, sym, ctrl, info)
89 #define UMFPACKWRAP_report_info umfpack_dl_report_info
90 #define UMFPACKWRAP_report_status umfpack_dl_report_status
91 #define UMFPACKWRAP_numeric umfpack_dl_numeric
92 #define UMFPACKWRAP_solve umfpack_dl_solve
94 #else // ! USE_UMFPACK_LONG
96 #define UMFPACKWRAP_defaults umfpack_di_defaults
97 #define UMFPACKWRAP_free_symbolic umfpack_di_free_symbolic
98 #define UMFPACKWRAP_free_numeric umfpack_di_free_numeric
100 #define UMFPACKWRAP_symbolic(size, app, aip, axp, sym, ctrl, info) \
101 umfpack_di_symbolic(size, size, app, aip, axp, sym, ctrl, info)
103 #define UMFPACKWRAP_report_info umfpack_di_report_info
104 #define UMFPACKWRAP_report_status umfpack_di_report_status
105 #define UMFPACKWRAP_numeric umfpack_di_numeric
106 #define UMFPACKWRAP_solve umfpack_di_solve
108 #endif // ! USE_UMFPACK_LONG
111 #define SYS_VALUE UMFPACK_A
112 #define SYS_VALUET UMFPACK_Aat
116 UmfpackSolver::UmfpackSolver(
const integer &size,
119 const unsigned blockSize,
132 memset(&Info[0], 0,
sizeof(Info));
133 UMFPACKWRAP_defaults(Control);
135 if (dPivot != -1. && (dPivot >= 0. && dPivot <= 1.)) {
142 Control[UMFPACK_PIVOT_TOLERANCE] = dPivot;
145 if (dDropTolerance != 0.) {
146 #ifdef UMFPACK_DROPTOL
147 ASSERT(dDropTolerance > 0.);
148 Control[UMFPACK_DROPTOL] = dDropTolerance;
153 Control[UMFPACK_BLOCK_SIZE] = blockSize;
156 if (scale != SCALE_UNDEF) {
157 Control[UMFPACK_SCALE] = scale;
161 Control[UMFPACK_IRSTEP] = iMaxIter;
165 UmfpackSolver::~UmfpackSolver(
void)
167 UMFPACKWRAP_free_symbolic(&Symbolic);
170 UMFPACKWRAP_free_numeric(&Numeric);
180 UMFPACKWRAP_free_numeric(&Numeric);
184 bHasBeenReset =
true;
188 UmfpackSolver::Solve(
void)
const
194 UmfpackSolver::SolveT(
void)
const
200 UmfpackSolver::Solve(
bool bTranspose)
const
203 const_cast<UmfpackSolver *
>(
this)->
Factor();
204 bHasBeenReset =
false;
213 #ifdef UMFPACK_REPORT
217 status = UMFPACKWRAP_solve((bTranspose ? SYS_VALUET : SYS_VALUE),
220 Numeric, Control, Info);
222 if (status != UMFPACK_OK) {
223 UMFPACKWRAP_report_info(Control, Info);
224 UMFPACKWRAP_report_status(Control, status) ;
225 silent_cerr(
"UMFPACKWRAP_solve failed" << std::endl);
228 UMFPACKWRAP_free_numeric(&Numeric);
234 if (Control[UMFPACK_IRSTEP] > 0 && Info[UMFPACK_IR_TAKEN] >= Control[UMFPACK_IRSTEP]) {
235 silent_cerr(
"warning: UMFPACK_IR_TAKEN = " << Info[UMFPACK_IR_TAKEN]
236 <<
" >= UMFPACK_IRSTEP = " << Control[UMFPACK_IRSTEP] << std::endl
237 <<
"\tThe flag \"max iterations\" of the linear solver is too small or the condition number of the Jacobian matrix is too high" << std::endl);
240 #ifdef UMFPACK_REPORT
241 UMFPACKWRAP_report_info(Control, Info);
247 UmfpackSolver::Factor(
void)
255 if (Symbolic == 0 && !bPrepareSymbolic()) {
259 #ifdef UMFPACK_REPORT
260 UMFPACKWRAP_report_symbolic (
"Symbolic factorization of A",
262 UMFPACKWRAP_report_info(Control, Info);
266 status = UMFPACKWRAP_numeric(App, Aip, Axp, Symbolic,
267 &Numeric, Control, Info);
268 if (status == UMFPACK_ERROR_different_pattern) {
269 UMFPACKWRAP_free_symbolic(&Symbolic);
270 if (!bPrepareSymbolic()) {
273 status = UMFPACKWRAP_numeric(App, Aip, Axp, Symbolic,
274 &Numeric, Control, Info);
277 if (status != UMFPACK_OK) {
278 UMFPACKWRAP_report_info(Control, Info);
279 UMFPACKWRAP_report_status(Control, status);
280 silent_cerr(
"UMFPACKWRAP_numeric failed" << std::endl);
283 UMFPACKWRAP_free_symbolic(&Symbolic);
284 UMFPACKWRAP_free_numeric(&Numeric);
292 #ifdef UMFPACK_REPORT
293 UMFPACKWRAP_report_numeric (
"Numeric factorization of A",
295 UMFPACKWRAP_report_info(Control, Info);
296 t1 = umfpack_timer() - t;
302 std::vector<doublereal>& Ax,
303 std::vector<integer>& Ai,
304 std::vector<integer>& Ac,
305 std::vector<integer>& Ap)
const
307 if (!bHasBeenReset) {
319 UmfpackSolver::bPrepareSymbolic(
void)
323 status = UMFPACKWRAP_symbolic(iSize, App, Aip, Axp,
324 &Symbolic, Control, Info);
325 if (status != UMFPACK_OK) {
326 UMFPACKWRAP_report_info(Control, Info) ;
327 UMFPACKWRAP_report_status(Control, status);
328 silent_cerr(
"UMFPACKWRAP_symbolic failed" << std::endl);
331 UMFPACKWRAP_free_symbolic(&Symbolic);
340 bool UmfpackSolver::bGetConditionNumber(
doublereal& dCond)
346 dCond = 1. / Info[UMFPACK_RCOND];
355 UmfpackSparseSolutionManager::UmfpackSparseSolutionManager(
integer Dim,
358 const unsigned blockSize,
369 UmfpackSolver::Scale uscale = UmfpackSolver::SCALE_UNDEF;
371 switch (scale.algorithm) {
373 scale.when = SCALEW_NEVER;
377 uscale = UmfpackSolver::SCALE_NONE;
378 scale.when = SCALEW_NEVER;
382 uscale = UmfpackSolver::SCALE_MAX;
383 scale.when = SCALEW_NEVER;
387 uscale = UmfpackSolver::SCALE_SUM;
388 scale.when = SCALEW_NEVER;
393 uscale = UmfpackSolver::SCALE_NONE;
397 UmfpackSolver(Dim, dPivot, dDropTolerance, blockSize, uscale, iMaxIter));
399 (void)pLS->pdSetResVec(&b[0]);
400 (void)pLS->pdSetSolVec(&x[0]);
401 pLS->SetSolutionManager(
this);
404 UmfpackSparseSolutionManager::~UmfpackSparseSolutionManager(
void)
413 UmfpackSparseSolutionManager::MatrReset(
void)
419 UmfpackSparseSolutionManager::MakeCompressedColumnForm(
void)
421 ScaleMatrixAndRightHandSide<SpMapMatrixHandler>(A);
423 pLS->MakeCompactForm(A, Ax, Ai, Adummy, Ap);
426 template <
typename MH>
427 void UmfpackSparseSolutionManager::ScaleMatrixAndRightHandSide(MH& mh)
429 if (scale.when != SCALEW_NEVER) {
442 rMatScale.
Report(std::cerr);
450 template <
typename MH>
453 if (pMatScale == 0) {
461 void UmfpackSparseSolutionManager::ScaleSolution(
void)
463 if (scale.when != SCALEW_NEVER) {
466 pMatScale->ScaleSolution(xVH);
472 UmfpackSparseSolutionManager::Solve(
void)
474 MakeCompressedColumnForm();
483 UmfpackSparseSolutionManager::SolveT(
void)
485 MakeCompressedColumnForm();
494 UmfpackSparseSolutionManager::pMatHdl(
void)
const
501 UmfpackSparseSolutionManager::pResHdl(
void)
const
508 UmfpackSparseSolutionManager::pSolHdl(
void)
const
516 UmfpackSparseCCSolutionManager<CC>::UmfpackSparseCCSolutionManager(
integer Dim,
519 const unsigned& blockSize,
520 const ScaleOpt& scale,
522 : UmfpackSparseSolutionManager(Dim, dPivot, dDropTolerance, blockSize, scale, iMaxIter),
530 UmfpackSparseCCSolutionManager<CC>::~UmfpackSparseCCSolutionManager(
void)
539 UmfpackSparseCCSolutionManager<CC>::MatrReset(
void)
546 UmfpackSparseCCSolutionManager<CC>::MakeCompressedColumnForm(
void)
549 pLS->MakeCompactForm(A, Ax, Ai, Adummy, Ap);
558 ScaleMatrixAndRightHandSide(*Ac);
564 UmfpackSparseCCSolutionManager<CC>::MatrInitialize()
583 UmfpackSparseCCSolutionManager<CC>::pMatHdl(
void)
const
593 template class UmfpackSparseCCSolutionManager<CColMatrixHandler<0> >;
594 template class UmfpackSparseCCSolutionManager<DirCColMatrixHandler<0> >;
virtual integer MakeCompressedColumnForm(doublereal *const Ax, integer *const Ai, integer *const Ap, int offset=0) const =0
#define MBDYN_EXCEPT_ARGS
bool bGetInitialized() const
bool ComputeScaleFactors(const T &mh)
std::ostream & Report(std::ostream &os) const
void Reset(scalar_func_type &d)
VectorHandler & ScaleRightHandSide(VectorHandler &bVH) const
#define ASSERT(expression)
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
static MatrixScale< T > * Allocate(const SolutionManager::ScaleOpt &scale)
T & ScaleMatrix(T &mh) const