Skip to content
Snippets Groups Projects
Commit 5227d84b authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

dg : minor opti in functionDerivator

parent 260d0871
No related branches found
No related tags found
No related merge requests found
...@@ -2,19 +2,20 @@ ...@@ -2,19 +2,20 @@
#include "function.h" #include "function.h"
const fullMatrix<double> &functionDerivator::compute() { const fullMatrix<double> &functionDerivator::compute() {
_xRef = _x.get(); const int nbColX = _x.get().size2();
const double o_eps = 1. / _epsilon;
_fRef = _f.get(); _fRef = _f.get();
_dfdx.resize(_fRef.size1(),_fRef.size2()*_xRef.size2(), false); _dfdx.resize(_fRef.size1(),_fRef.size2() * nbColX, false);
for (int j=0;j<_xRef.size2();j++) { for (int j = 0; j < nbColX; ++j) {
fullMatrix<double> &x =_x.set(); fullMatrix<double> &x =_x.set();
for (int i=0;i<_fRef.size1();i++) for (int i=0;i<_fRef.size1();i++)
x(i,j) += _epsilon; x(i,j) += _epsilon;
const fullMatrix<double> &f = _f.get(); const fullMatrix<double> &f = _f.get();
for (int k=0; k<_fRef.size2(); k++) for (int k=0; k<_fRef.size2(); k++)
for (int i=0; i<_fRef.size1(); i++) for (int i=0; i<_fRef.size1(); i++)
_dfdx(i, k*_xRef.size2()+j) = (f(i,k)-_fRef(i,k))/_epsilon; _dfdx(i, k * nbColX + j) = (f(i,k)-_fRef(i,k)) * o_eps;
for (int i=0;i<_fRef.size1();i++) for (int i=0;i<_fRef.size1();i++)
x(i,j) = _xRef(i,j); x(i,j) -= _epsilon;
} }
_x.set(); _x.set();
return _dfdx; return _dfdx;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment