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

[SofaGeneralAnimationLoop, Sofa.SimulationCore] Extract MechanicalAccumulateJacobian #2481

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions SofaKernel/modules/SofaSimulationCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ set(HEADER_FILES

${SRC_ROOT}/mechanicalvisitor/MechanicalAccFromFVisitor.h
${SRC_ROOT}/mechanicalvisitor/MechanicalAccumulateConstraint.h
${SRC_ROOT}/mechanicalvisitor/MechanicalAccumulateJacobian.h
${SRC_ROOT}/mechanicalvisitor/MechanicalAccumulateMatrixDeriv.h
${SRC_ROOT}/mechanicalvisitor/MechanicalAddMBKdxVisitor.h
${SRC_ROOT}/mechanicalvisitor/MechanicalAddMBK_ToMatrixVisitor.h
Expand Down Expand Up @@ -198,6 +199,7 @@ set(SOURCE_FILES

${SRC_ROOT}/mechanicalvisitor/MechanicalAccFromFVisitor.cpp
${SRC_ROOT}/mechanicalvisitor/MechanicalAccumulateConstraint.cpp
${SRC_ROOT}/mechanicalvisitor/MechanicalAccumulateJacobian.cpp
${SRC_ROOT}/mechanicalvisitor/MechanicalAccumulateMatrixDeriv.cpp
${SRC_ROOT}/mechanicalvisitor/MechanicalAddMBKdxVisitor.cpp
${SRC_ROOT}/mechanicalvisitor/MechanicalAddMBK_ToMatrixVisitor.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/

#include <sofa/simulation/mechanicalvisitor/MechanicalAccumulateJacobian.h>
#include <sofa/core/ConstraintParams.h>
#include <sofa/core/BaseMapping.h>

namespace sofa::simulation::mechanicalvisitor
{

MechanicalAccumulateJacobian::MechanicalAccumulateJacobian(const core::ConstraintParams* _cparams,
core::MultiMatrixDerivId _res)
: simulation::BaseMechanicalVisitor(_cparams)
, res(_res)
, cparams(_cparams)
{}

void MechanicalAccumulateJacobian::bwdMechanicalMapping(simulation::Node* node, core::BaseMapping* map)
{
const ctime_t t0 = begin(node, map);
map->applyJT(cparams, res, res);
end(node, map, t0);
}

} //namespace sofa::simulation::mechanicalvisitor
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#pragma once

#include <sofa/simulation/BaseMechanicalVisitor.h>

namespace sofa::simulation::mechanicalvisitor
{

alxbilger marked this conversation as resolved.
Show resolved Hide resolved
class SOFA_SIMULATION_CORE_API MechanicalAccumulateJacobian : public simulation::BaseMechanicalVisitor
{
public:
MechanicalAccumulateJacobian(const core::ConstraintParams* _cparams, core::MultiMatrixDerivId _res);

void bwdMechanicalMapping(simulation::Node* node, core::BaseMapping* map) override;

/// Return a class name for this visitor
/// Only used for debugging / profiling purposes
const char* getClassName() const override { return "MechanicalAccumulateJacobian"; }

bool isThreadSafe() const override
{
return false;
}
// This visitor must go through all mechanical mappings, even if isMechanical flag is disabled
bool stopAtMechanicalMapping(simulation::Node* /*node*/, core::BaseMapping* /*map*/) override
{
return false; // !map->isMechanical();
}

protected:
core::MultiMatrixDerivId res;
const sofa::core::ConstraintParams *cparams;
};

} //namespace sofa::simulation::mechanicalvisitor
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,15 @@

#include <sofa/core/topology/BaseMeshTopology.h>

#include <sofa/simulation/MechanicalVisitor.h>

#include <sofa/core/MultiVecId.h>
#include <sofa/core/BaseMapping.h>
#include <sofa/linearalgebra/SparseMatrixProduct[EigenSparseMatrix].h>

namespace sofa::component::interactionforcefield
namespace sofa::simulation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to not forward declare things manually, including sofa/simulation/fwd.h.

{
class Node;
}

class SOFA_SOFAGENERALANIMATIONLOOP_API MechanicalAccumulateJacobian : public simulation::BaseMechanicalVisitor
namespace sofa::component::interactionforcefield
{
public:
MechanicalAccumulateJacobian(const core::ConstraintParams* _cparams, core::MultiMatrixDerivId _res)
: simulation::BaseMechanicalVisitor(_cparams)
, res(_res)
, cparams(_cparams)
{}

void bwdMechanicalMapping(simulation::Node* node, core::BaseMapping* map) override
{
ctime_t t0 = begin(node, map);
map->applyJT(cparams, res, res);
end(node, map, t0);
}

/// Return a class name for this visitor
/// Only used for debugging / profiling purposes
const char* getClassName() const override { return "MechanicalAccumulateJacobian"; }

bool isThreadSafe() const override
{
return false;
}
// This visitor must go through all mechanical mappings, even if isMechanical flag is disabled
bool stopAtMechanicalMapping(simulation::Node* /*node*/, core::BaseMapping* /*map*/) override
{
return false; // !map->isMechanical();
}

protected:
core::MultiMatrixDerivId res;
const sofa::core::ConstraintParams *cparams;
};

using sofa::core::objectmodel::BaseObject ;
using sofa::component::linearsolver::CompressedRowSparseMatrix ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@
#include <sofa/helper/ScopedAdvancedTimer.h>
#include <sofa/linearalgebra/SparseMatrixProduct[EigenSparseMatrix].h>

// accumulate jacobian

#include <sofa/core/objectmodel/BaseContext.h>
#include <sofa/core/behavior/MechanicalState.h>
#include <sofa/core/behavior/BaseMass.h>
#include <sofa/defaulttype/MapMapSparseMatrix.h>

#include <sofa/simulation/mechanicalvisitor/MechanicalResetConstraintVisitor.h>
using sofa::simulation::mechanicalvisitor::MechanicalResetConstraintVisitor;
#include <sofa/simulation/mechanicalvisitor/MechanicalAccumulateJacobian.h>

#include <sofa/core/MechanicalParams.h>

#include <sofa/simulation/CpuTask.h>
#include <sofa/simulation/TaskScheduler.h>
using sofa::simulation::mechanicalvisitor::MechanicalResetConstraintVisitor;

// verify timing
#include <sofa/helper/system/thread/CTime.h>
Expand Down Expand Up @@ -193,7 +194,7 @@ void MechanicalMatrixMapper<DataTypes1, DataTypes2>::bwdInit()
}

template<class DataTypes1, class DataTypes2>
void MechanicalMatrixMapper<DataTypes1, DataTypes2>::parseNode(sofa::simulation::Node *node,std::string massName)
void MechanicalMatrixMapper<DataTypes1, DataTypes2>::parseNode(sofa::simulation::Node *node, std::string massName)
{
bool empty = d_forceFieldList.getValue().empty();
msg_info() << "parsing node:";
Expand Down Expand Up @@ -261,7 +262,7 @@ void MechanicalMatrixMapper<DataTypes1, DataTypes2>::accumulateJacobians(const M
MechanicalResetConstraintVisitor(&cparams).execute(context);
buildIdentityBlocksInJacobian(l_mechanicalState,Id);

MechanicalAccumulateJacobian(&cparams, core::MatrixDerivId::mappingJacobian()).execute(gnode);
sofa::simulation::mechanicalvisitor::MechanicalAccumulateJacobian(&cparams, core::MatrixDerivId::mappingJacobian()).execute(gnode);
}

template<class T>
Expand Down