39 #include <sys/types.h>
56 dMinPiv(dMP < 0 ? 0 : dMP),
94 silent_cerr(
"NaiveSolver: ERANGE"
99 silent_cerr(
"NaiveSolver: (" << rc <<
")"
123 silent_cerr(
"NaiveSolver: ENULCOL(" << idx <<
")"
128 silent_cerr(
"NaiveSolver: ENOPIV(" << idx <<
")"
133 silent_cerr(
"NaiveSolver: ERANGE"
138 silent_cerr(
"NaiveSolver: (" << rc <<
")"
214 rMatScale.
Report(std::cerr);
222 template <
typename MH>
286 dMinPiv(dMP < 0 ? 0 : dMP),
314 if (ePermState == PERM_INTERMEDIATE) {
315 ePermState = PERM_READY;
329 ASSERT(pd != TmpH.pdGetVec());
331 for (
integer i = 0; i < A->iGetNumCols(); i++) {
345 ScaleMatrixAndRightHandSide(dynamic_cast<NaivePermMatrixHandler&>(*A));
347 if (ePermState == PERM_NO) {
348 ComputePermutation();
350 }
else if (ePermState == PERM_READY) {
353 pd = pLS->pdSetSolVec(TmpH.pdGetVec());
358 if (ePermState == PERM_READY) {
362 pLS->pdSetSolVec(pd);
373 ePermState = PERM_NO;
374 for (
integer i = 0; i < A->iGetNumRows(); i++) {
392 std::vector<integer> Ai;
393 A->MakeCCStructure(Ai,
invperm);
400 if (!
mbdyn_colamd(A->iGetNumRows(), A->iGetNumCols(), Alen,
401 &Ai[0], &
invperm[0], knobs, stats))
403 silent_cerr(
"colamd permutation failed" << std::endl);
406 for (
integer i = 0; i < A->iGetNumRows(); i++) {
407 perm[invperm[i]] = i;
409 ePermState = PERM_INTERMEDIATE;
415 #include "boost/config.hpp"
416 #include "boost/graph/adjacency_list.hpp"
417 #include "boost/graph/properties.hpp"
418 #include "boost/graph/bandwidth.hpp"
419 #include <boost/graph/wavefront.hpp>
421 #ifdef HAVE_BOOST_GRAPH_CUTHILL_MCKEE_ORDERING_HPP
422 #include "boost/graph/cuthill_mckee_ordering.hpp"
424 #ifdef HAVE_BOOST_GRAPH_KING_ORDERING_HPP
425 #include "boost/graph/king_ordering.hpp"
427 #ifdef HAVE_BOOST_GRAPH_MINIMUM_DEGREE_ORDERING_HPP
428 #include <boost/graph/sloan_ordering.hpp>
430 #ifdef HAVE_BOOST_GRAPH_SLOAN_ORDERING_HPP
431 #include "boost/graph/minimum_degree_ordering.hpp"
434 #ifdef HAVE_BOOST_GRAPH_CUTHILL_MCKEE_ORDERING_HPP
439 std::vector<integer> Ai;
440 std::vector<integer> Ac;
443 invperm.resize(A->iGetNumCols());
444 A->MakeCCStructure(Ai, Ac);
449 typedef boost::adjacency_list<
454 boost::vertex_color_t,
455 boost::default_color_type,
457 boost::vertex_degree_t,
467 typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
468 typedef boost::graph_traits<Graph>::vertices_size_type size_type;
471 Graph G(A->iGetNumRows());
472 for (
int col=0; col<A->iGetNumCols(); col++) {
473 for (
int i = Ac[col]; i < Ac[col + 1]; i++) {
476 boost::add_edge(row, col, G);
477 boost::add_edge(col, row, G);
483 std::vector<Vertex> inv_perm(num_vertices(G));
484 boost::cuthill_mckee_ordering(G, inv_perm.rbegin());
486 boost::sloan_ordering(G, inv_perm.rbegin(),
487 boost::get(boost::vertex_color, G),
488 boost::make_degree_map(G),
489 boost::get(boost::vertex_priority, G));
492 for (
integer i = 0; i < A->iGetNumRows(); i++) {
496 ePermState = PERM_INTERMEDIATE;
500 #ifdef HAVE_BOOST_GRAPH_SLOAN_ORDERING_HPP
505 std::vector<integer> Ai;
506 std::vector<integer> Ac;
509 invperm.resize(A->iGetNumCols());
510 A->MakeCCStructure(Ai, Ac);
515 typedef boost::adjacency_list<
520 boost::vertex_color_t,
521 boost::default_color_type,
523 boost::vertex_degree_t,
526 boost::vertex_priority_t,
532 typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
533 typedef boost::graph_traits<Graph>::vertices_size_type size_type;
536 Graph G(A->iGetNumRows());
537 for (
int col=0; col<A->iGetNumCols(); col++) {
538 for (
int i = Ac[col]; i < Ac[col + 1]; i++) {
541 boost::add_edge(row, col, G);
542 boost::add_edge(col, row, G);
548 std::vector<Vertex> inv_perm(num_vertices(G));
549 std::vector<Vertex> _perm(num_vertices(G));
550 boost::sloan_ordering(G, _perm.begin(),
551 boost::get(boost::vertex_color, G),
552 boost::make_degree_map(G),
553 boost::get(boost::vertex_priority, G));
555 for (integer i = 0; i < A->iGetNumRows(); i++) {
561 ePermState = PERM_INTERMEDIATE;
565 #ifdef HAVE_BOOST_GRAPH_KING_ORDERING_HPP
570 std::vector<integer> Ai;
571 std::vector<integer> Ac;
574 invperm.resize(A->iGetNumCols());
575 A->MakeCCStructure(Ai, Ac);
580 typedef boost::adjacency_list<
585 boost::vertex_color_t,
586 boost::default_color_type,
588 boost::vertex_degree_t,
593 typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
594 typedef boost::graph_traits<Graph>::vertices_size_type size_type;
597 Graph G(A->iGetNumRows());
598 for (
int col=0; col<A->iGetNumCols(); col++) {
599 for (
int i = Ac[col]; i < Ac[col + 1]; i++) {
602 boost::add_edge(row, col, G);
603 boost::add_edge(col, row, G);
608 std::vector<Vertex> inv_perm(num_vertices(G));
609 boost::king_ordering(G, inv_perm.rbegin());
611 for (integer i = 0; i < A->iGetNumRows(); i++) {
615 ePermState = PERM_INTERMEDIATE;
619 #ifdef HAVE_BOOST_GRAPH_MINIMUM_DEGREE_ORDERING_HPP
624 std::vector<integer> Ai;
625 std::vector<integer> Ac;
628 invperm.resize(A->iGetNumCols());
629 A->MakeCCStructure(Ai, Ac);
631 typedef boost::adjacency_list<
636 typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
637 typedef boost::graph_traits<Graph>::vertices_size_type size_type;
640 Graph G(A->iGetNumRows());
641 for (
int col=0; col<A->iGetNumCols(); col++) {
642 for (
int i = Ac[col]; i < Ac[col + 1]; i++) {
645 boost::add_edge(row, col, G);
646 boost::add_edge(col, row, G);
651 boost::property_map<Graph, boost::vertex_index_t>::type
652 id = boost::get(boost::vertex_index, G);
653 std::vector<Vertex> inv_perm(num_vertices(G));
654 std::vector<Vertex> _perm(num_vertices(G));
655 std::vector<integer> degree(A->iGetNumRows(), 0);
656 std::vector<integer> supernode_sizes(A->iGetNumRows(), 1);
659 boost::minimum_degree_ordering(
661 make_iterator_property_map(°ree[0],
id, degree[0]),
664 boost::make_iterator_property_map(
677 ePermState = PERM_INTERMEDIATE;
694 std::vector<integer> Ai;
695 std::vector<integer> Ac;
698 invperm.resize(A->iGetNumCols());
699 A->MakeCCStructure(Ai, Ac);
704 typedef std::set<integer> row_cont_type;
705 std::vector<row_cont_type> col_indices(A->iGetNumCols());
709 integer ncols = A->iGetNumCols();
710 for (integer col_id=0; col_id<ncols; col_id++) {
711 for (integer i=Ac[col_id]; i<Ac[col_id+1]; i++) {
713 if (row_id != col_id) {
715 row_cont_type& row1 = col_indices[col_id];
716 if (row1.find(row_id) == row1.end()) {
721 row_cont_type& row2 = col_indices[row_id];
722 if (row2.find(col_id) == row2.end()) {
733 row_cont_type::iterator ri;
734 row_cont_type::const_iterator re;
735 integer NCols = A->iGetNumCols();
736 for (integer col = 0; col < NCols; col++) {
738 re = col_indices[col].end();
739 for (ri = col_indices[col].
begin(); ri != re; ri++) {
747 int n = A->iGetNumCols();
748 int options[8] = {1, 3, 1, 3, 0, 1, 200, 3};
752 ePermState = PERM_INTERMEDIATE;
790 #ifdef HAVE_BOOST_GRAPH_CUTHILL_MCKEE_ORDERING_HPP
793 #ifdef HAVE_BOOST_GRAPH_KING_ORDERING_HPP
796 #ifdef HAVE_BOOST_GRAPH_MINIMUM_DEGREE_ORDERING_HPP
799 #ifdef HAVE_BOOST_GRAPH_SLOAN_ORDERING_HPP
MatrixScaleBase * pMatScale
NaiveSolver(const integer &size, const doublereal &dMP, NaiveMatrixHandler *const a=0)
virtual MatrixHandler * pMatHdl(void) const
void SetMat(NaiveMatrixHandler *const a)
virtual ~NaiveSparsePermSolutionManager(void)
#define MBDYN_EXCEPT_ARGS
virtual ~NaiveSparseSolutionManager(void)
void METIS_NodeND(int *, int *, int *, int *, int *, int *, int *)
virtual void MatrInitialize(void)
void ScaleMatrixAndRightHandSide(MH &mh)
bool bGetInitialized() const
virtual MyVectorHandler * pSolHdl(void) const
virtual MyVectorHandler * pResHdl(void) const
virtual void MatrReset(void)
void mbdyn_colamd_set_defaults(double knobs[20])
bool ComputeScaleFactors(const T &mh)
std::ostream & Report(std::ostream &os) const
void SetSolutionManager(SolutionManager *pSM)
const std::vector< integer > & perm
std::vector< integer > invperm
doublereal * pdSetResVec(doublereal *pd)
int naivfct(RMAT a, integer neq, integer *nzr, IMAT ri, integer *nzc, IMAT ci, NZMAT nz, integer *piv, doublereal minpiv)
doublereal * pdSetSolVec(doublereal *pd)
virtual void MatrReset(void)
integer mbdyn_colamd_recommended(integer nnz, integer n_row, integer n_col)
integer mbdyn_colamd(integer n_row, integer n_col, integer Alen, integer A[], integer p[], double knobs[20], integer stats[20])
NaiveMatrixHandler(const NaiveMatrixHandler &)
NaiveSparseSolutionManager(const integer Dim, const doublereal dMP=1.e-9, const ScaleOpt &scale=ScaleOpt())
MatrixScale< MH > & GetMatrixScale()
VectorHandler & ScaleRightHandSide(VectorHandler &bVH) const
#define ASSERT(expression)
virtual void Solve(void) const =0
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
NaiveSparsePermSolutionManager(const integer Dim, const doublereal dMP=1.e-9, const ScaleOpt &scale=ScaleOpt())
std::vector< integer > piv
NaivePermMatrixHandler(integer iSize, const std::vector< integer > &tperm, const std::vector< integer > &invperm)
static MatrixScale< T > * Allocate(const SolutionManager::ScaleOpt &scale)
const std::vector< integer > & invperm
static const doublereal a
void ComputePermutation(void)
virtual doublereal * pdGetVec(void) const
std::vector< integer > perm
VectorHandler & ScaleSolution(VectorHandler &xVH) const
NaivePermMatrixHandler::const_iterator begin(void) const
int naivslv(RMAT a, integer neq, integer *nzc, IMAT ci, doublereal *rhs, doublereal *sol, integer *piv)
T & ScaleMatrix(T &mh) const