Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SofaBaseLinearSolver] CLEAN GraphScatteredTypes #844

Merged
merged 1 commit into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 21 additions & 28 deletions SofaKernel/modules/SofaBaseLinearSolver/GraphScatteredTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <SofaBaseLinearSolver/GraphScatteredTypes.h>
#include <sofa/core/visual/VisualParams.h>
#include <sofa/simulation/MechanicalVisitor.h>
#include <sofa/simulation/MechanicalMatrixVisitor.h>
#include <sofa/simulation/MechanicalVPrintVisitor.h>
#include <sofa/simulation/VelocityThresholdVisitor.h>
#include <sofa/core/behavior/LinearSolver.h>

#include <stdlib.h>
#include <math.h>
Expand All @@ -44,38 +40,35 @@ using sofa::core::objectmodel::BaseContext;

void GraphScatteredMatrix::apply(GraphScatteredVector& res, GraphScatteredVector& x)
{
// matrix-vector product
#if 1
// new more powerful visitors
// matrix-vector product through visitors
parent->propagateDxAndResetDf(x,res);
parent->addMBKdx(res,parent->mparams.mFactor(),parent->mparams.bFactor(),parent->mparams.kFactor(), false); // df = (m M + b B + k K) dx

#else
parent->propagateDx(x); // dx = p
parent->computeDf(res); // q = K p

if (parent->mparams.kFactor() != 1.0)
res *= parent->mparams.kFactor(); // q = k K p

// apply global Rayleigh damping
if (parent->mparams.mFactor() == 1.0)
{
parent->addMdx(res); // no need to propagate p as dx again
}
else if (parent->mparams.mFactor() != 0.0)
{
parent->addMdx(res,core::MultiVecDerivId(),parent->mparams.mFactor()); // no need to propagate p as dx again
}
// q = (m M + k K) p

/// @TODO: any damping (i.e. the B factor & rayleigh)
#endif

// filter the product to take the constraints into account
//
parent->projectResponse(res); // q is projected to the constrained space
}

unsigned int GraphScatteredMatrix::rowSize()
{
unsigned int nbRow=0, nbCol=0;
this->parent->getMatrixDimension(&nbRow, &nbCol);
return nbRow;

}

unsigned int GraphScatteredMatrix::colSize()
{
unsigned int nbRow=0, nbCol=0;
this->parent->getMatrixDimension(&nbRow, &nbCol);
return nbCol;
}


void GraphScatteredVector::operator=(const MultExpr<GraphScatteredMatrix,GraphScatteredVector>& expr)
{
expr.a.apply(*this,expr.b);
}

} // namespace linearsolver

Expand Down
38 changes: 7 additions & 31 deletions SofaKernel/modules/SofaBaseLinearSolver/GraphScatteredTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
#include <sofa/simulation/MechanicalOperations.h>
#include <sofa/core/behavior/MultiVec.h>
#include <sofa/core/behavior/LinearSolver.h>
#include <SofaBaseLinearSolver/SparseMatrix.h>
#include <SofaBaseLinearSolver/FullMatrix.h>


namespace sofa
{
Expand All @@ -53,19 +52,14 @@ class SOFA_BASE_LINEAR_SOLVER_API GraphScatteredMatrix
{
public:
typedef SReal Real;
//simulation::SolverImpl* parent;
//double mFact, bFact, kFact;
core::MechanicalParams mparams;
simulation::common::MechanicalOperations* parent;
public:
GraphScatteredMatrix()
: parent(NULL) //, mFact(0.0), bFact(0.0), kFact(0.0)
{
}
void setMBKFacts(const core::MechanicalParams* mparams)
: parent(nullptr)
{
this->mparams = *mparams;
}
void setMBKFacts(const core::MechanicalParams* mparams){ this->mparams = *mparams;}
MultExpr<GraphScatteredMatrix,GraphScatteredVector> operator*(GraphScatteredVector& v)
{
return MultExpr<GraphScatteredMatrix,GraphScatteredVector>(*this, v);
Expand All @@ -74,21 +68,9 @@ class SOFA_BASE_LINEAR_SOLVER_API GraphScatteredMatrix


// compatibility with baseMatrix
unsigned int rowSize()
{
unsigned int nbRow=0, nbCol=0;
this->parent->getMatrixDimension(&nbRow, &nbCol);
return nbRow;
unsigned int rowSize(); /// provides the number of rows of the Graph Scattered Matrix

}
int colSize()
{
unsigned int nbRow=0, nbCol=0;
this->parent->getMatrixDimension(&nbRow, &nbCol);
return nbCol;
}

//void papply(GraphScatteredVector& res, GraphScatteredVector& x);
unsigned int colSize(); /// provides the number of columns of the Graph Scattered Matrix

static const char* Name() { return "GraphScattered"; }
};
Expand Down Expand Up @@ -141,15 +123,9 @@ class SOFA_BASE_LINEAR_SOLVER_API GraphScatteredVector : public sofa::core::beha

friend class GraphScatteredMatrix;

void operator=(const MultExpr<GraphScatteredMatrix,GraphScatteredVector>& expr)
{
expr.a.apply(*this,expr.b);
}
void operator=(const MultExpr<GraphScatteredMatrix,GraphScatteredVector>& expr);


//void operator+=(const MultExpr<GraphScatteredMatrix,GraphScatteredVector>& expr)
//{
// expr.a.papply(*this,expr.b);
//}

static const char* Name() { return "GraphScattered"; }
};
Expand Down