<commit_before>#include "LDLTSolver.h"
#include "LDLTResponse.h"

#include <sofa/core/ObjectFactory.h>

#include "../utils/sparse.h"

#include <Eigen/SparseCholesky>
#include "SubKKT.h"

using std::cerr;
using std::endl;

namespace sofa {
namespace component {
namespace linearsolver {

SOFA_DECL_CLASS(LDLTSolver)
static int LDLTSolverClass = core::RegisterObject("Direct LDLT solver").add< LDLTSolver >();

typedef AssembledSystem::vec vec;


struct LDLTSolver::pimpl_type {
    typedef Eigen::SimplicialLDLT< cmat >  solver_type;

    solver_type solver;
    cmat PHinvPJT;
    cmat schur;

    cmat tmp;
    
    SubKKT sub;
};



LDLTSolver::LDLTSolver() 
    : schur(initData(&schur,
                     true,
                     "schur",
                     "use schur complement"))
    , pimpl( new pimpl_type )
{

}

LDLTSolver::~LDLTSolver() {
    
}


void LDLTSolver::init() {

    KKTSolver::init();

    // let's find a response
    response = this->getContext()->get<Response>( core::objectmodel::BaseContext::Local );

    // fallback in case we missed
    if( !response ) {
        response = new LDLTResponse();
        this->getContext()->addObject( response );
        
        serr << "fallback response class: "
             << response->getClassName()
             << " added to the scene" << sendl;
    }
}


void LDLTSolver::factor(const AssembledSystem& sys) {

    if( schur.getValue() ) {
        factor_schur( sys );
    } else {
        SubKKT::projected_kkt(pimpl->sub, sys, 1e-14);
        pimpl->sub.factor(*response);
    }
}

void LDLTSolver::solve(vec& res,
                       const AssembledSystem& sys,
                       const vec& rhs) const {
    if( schur.getValue() ) {
        solve_schur(res, sys, rhs);
    } else {
        solve_kkt(res, sys, rhs);
    }

}



void LDLTSolver::factor_schur( const AssembledSystem& sys ) {
<commit_msg>Compliant: (LDLTSolver) only fill lower triangular part during full kkt factor<commit_after>#include "LDLTSolver.h"
#include "LDLTResponse.h"

#include <sofa/core/ObjectFactory.h>

#include "../utils/sparse.h"

#include <Eigen/SparseCholesky>
#include "SubKKT.h"

using std::cerr;
using std::endl;

namespace sofa {
namespace component {
namespace linearsolver {

SOFA_DECL_CLASS(LDLTSolver)
static int LDLTSolverClass = core::RegisterObject("Direct LDLT solver").add< LDLTSolver >();

typedef AssembledSystem::vec vec;


struct LDLTSolver::pimpl_type {
    typedef Eigen::SimplicialLDLT< cmat >  solver_type;

    solver_type solver;
    cmat PHinvPJT;
    cmat schur;

    cmat tmp;
    
    SubKKT sub;
};



LDLTSolver::LDLTSolver() 
    : schur(initData(&schur,
                     true,
                     "schur",
                     "use schur complement"))
    , pimpl( new pimpl_type )
{

}

LDLTSolver::~LDLTSolver() {
    
}


void LDLTSolver::init() {

    KKTSolver::init();

    // let's find a response
    response = this->getContext()->get<Response>( core::objectmodel::BaseContext::Local );

    // fallback in case we missed
    if( !response ) {
        response = new LDLTResponse();
        this->getContext()->addObject( response );
        
        serr << "fallback response class: "
             << response->getClassName()
             << " added to the scene" << sendl;
    }
}


void LDLTSolver::factor(const AssembledSystem& sys) {

    if( schur.getValue() ) {
        factor_schur( sys );
    } else {
        SubKKT::projected_kkt(pimpl->sub, sys, 1e-14, true);
        pimpl->sub.factor(*response);
    }
}

void LDLTSolver::solve(vec& res,
                       const AssembledSystem& sys,
                       const vec& rhs) const {
    if( schur.getValue() ) {
        solve_schur(res, sys, rhs);
    } else {
        solve_kkt(res, sys, rhs);
    }

}



void LDLTSolver::factor_schur( const AssembledSystem& sys ) {

{'fraction_non_alphanumeric': 0.12859735545760953, 'fraction_numerical': 0.00155561317085818, 'mean_word_length': 2.565619223659889, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5830111', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1245, 'n_words': 269}