-
Notifications
You must be signed in to change notification settings - Fork 298
/
ManualLinearMapping.inl
108 lines (80 loc) · 4.08 KB
/
ManualLinearMapping.inl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/******************************************************************************
* 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 *
******************************************************************************/
#ifndef SOFA_COMPONENT_MAPPING_MANUALLINEARMAPPING_INL
#define SOFA_COMPONENT_MAPPING_MANUALLINEARMAPPING_INL
#include "ManualLinearMapping.h"
#include <sofa/defaulttype/VecTypes.h>
#include <sofa/core/Mapping.inl>
namespace sofa::component::mapping
{
// _matrixJ must have been filled before calling init()
template<class TIn, class TOut>
void ManualLinearMapping<TIn, TOut>::init()
{
Inherit::init();
// init js
js.clear();
js.push_back(&_matrixJ);
// resize output
this->toModel->resize( _matrixJ.rowSize() / NOut );
}
template <class TIn, class TOut>
void ManualLinearMapping<TIn, TOut>::apply(const core::MechanicalParams * /*mparams*/ /* PARAMS FIRST */, Data<VecCoord>& dOut, const Data<InVecCoord>& dIn)
{
// if( !_matrixJ.colSize() && !_matrixJ.rowSize() ) return;
auto waOut = sofa::helper::getWriteOnlyAccessor(dOut);
auto raIn = sofa::helper::getReadAccessor(dIn);
_matrixJ.mult( *reinterpret_cast<VecDeriv*>(&(waOut.wref())), *reinterpret_cast<const InVecDeriv*>(&(raIn.ref())) );
}
template <class TIn, class TOut>
void ManualLinearMapping<TIn, TOut>::applyJ(const core::MechanicalParams * /*mparams*/ /* PARAMS FIRST */, Data<VecDeriv>& dOut, const Data<InVecDeriv>& dIn)
{
// if( !_matrixJ.colSize() && !_matrixJ.rowSize() ) return;
auto waOut = sofa::helper::getWriteOnlyAccessor(dOut);
auto raIn = sofa::helper::getReadAccessor(dIn);
_matrixJ.mult(waOut.wref(), raIn.ref());
}
template<class TIn, class TOut>
void ManualLinearMapping<TIn, TOut>::applyJT(const core::MechanicalParams * /*mparams*/ /* PARAMS FIRST */, Data<InVecDeriv>& dOut, const Data<VecDeriv>& dIn)
{
// if( !_matrixJ.colSize() && !_matrixJ.rowSize() ) return;
auto waOut = sofa::helper::getWriteOnlyAccessor(dOut);
auto raIn = sofa::helper::getReadAccessor(dIn);
_matrixJ.addMultTranspose( waOut.wref(), raIn.ref());
}
template <class TIn, class TOut>
void ManualLinearMapping<TIn, TOut>::applyJT(const core::ConstraintParams * /*cparams*/ /* PARAMS FIRST */, Data<InMatrixDeriv>& /*dOut*/, const Data<MatrixDeriv>& /*dIn*/)
{
// serr<<SOFA_CLASS_METHOD<<"not yet implemented"<<sendl;
}
template <class TIn, class TOut>
const sofa::linearalgebra::BaseMatrix* ManualLinearMapping<TIn, TOut>::getJ()
{
return &_matrixJ;
}
template <class TIn, class TOut>
const typename ManualLinearMapping<TIn, TOut>::js_type* ManualLinearMapping<TIn, TOut>::getJs()
{
return &js;
}
} // namespace sofa::component::mapping
#endif