cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nmrFnJacobianSolver.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Ankur Kapoor
7  Created on: 2004-10-26
8 
9  (C) Copyright 2004-2007 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 */
20 
21 
28 #ifndef _nmrFnJacobianSolver_h
29 #define _nmrFnJacobianSolver_h
30 
31 
33 
34 #include <cnetlib.h>
35 
103  // we have this class so that we reserve memory only one
104  // would help if svd of a same size matrix (or a matrix)
105  // that doesnt change much is desired.
106 
107 protected:
108  CISSTNETLIB_INTEGER N;
109  CISSTNETLIB_INTEGER Ldfjac;
110  CISSTNETLIB_DOUBLE Tolerance;
111  CISSTNETLIB_INTEGER Info;
112  CISSTNETLIB_INTEGER Lwork;
114 
115 public:
121  {
122  Allocate(0);
123  }
124 
125 
134  nmrFnJacobianSolver(CISSTNETLIB_INTEGER n)
135  {
136  Allocate(n);
137  }
138 
139 
147  Allocate(X);
148  }
150 
151 
158  inline void Allocate(CISSTNETLIB_INTEGER n) {
159  N = n;
160  Lwork = N*(N+13)/2;
161  Ldfjac = N;
162  Tolerance = 1e-6;
163  Work.SetSize(Lwork);
164  }
165 
166 
173  Allocate(X.size());
174  }
176 
177 
186  template <int __instanceLineF, class __elementTypeF, int __instanceLineJ, class __elementTypeJ>
190  vctDynamicVector<CISSTNETLIB_DOUBLE> &J, CISSTNETLIB_DOUBLE tolerance) throw (std::runtime_error) {
191  if ((N != static_cast<CISSTNETLIB_INTEGER>(X.size())) || (N != static_cast<CISSTNETLIB_INTEGER>(F.size())) || (Ldfjac*N != static_cast<CISSTNETLIB_INTEGER>(J.size()))) {
192  cmnThrow(std::runtime_error("nmrFnJacobianSolver Solve: Size used for Allocate was different"));
193  }
194  Tolerance = tolerance;
195  /* call the MINPACK C function */
196  hybrj2_(callBackF.FunctionFhybrd, callBackJ.FunctionFhybrj2, &N,
197  X.Pointer(), F.Pointer(), J.Pointer(),
198  &Ldfjac, &Tolerance, &Info,
199  Work.Pointer(), &Lwork);
200  }
202 
203 };
204 
205 #endif // _nmrFnJacobianSolver_h
206 
Definition: nmrFnJacobianSolver.h:102
Declaration of vctDynamicMatrix.
CISSTNETLIB_INTEGER Lwork
Definition: nmrFnJacobianSolver.h:112
void Allocate(CISSTNETLIB_INTEGER n)
Definition: nmrFnJacobianSolver.h:158
nmrFnJacobianSolver(void)
Definition: nmrFnJacobianSolver.h:120
CISSTNETLIB_INTEGER Info
Definition: nmrFnJacobianSolver.h:111
void SetSize(size_type size)
Definition: vctDynamicVector.h:315
void Solve(nmrCallBackFunctionF< __instanceLineF, __elementTypeF > &callBackF, nmrCallBackFunctionJ< __instanceLineJ, __elementTypeJ > &callBackJ, vctDynamicVector< CISSTNETLIB_DOUBLE > &X, vctDynamicVector< CISSTNETLIB_DOUBLE > &F, vctDynamicVector< CISSTNETLIB_DOUBLE > &J, CISSTNETLIB_DOUBLE tolerance)
Definition: nmrFnJacobianSolver.h:187
size_type size(void) const
Definition: vctDynamicConstVectorBase.h:164
Definition: nmrCallBack.h:45
nmrFnJacobianSolver(CISSTNETLIB_INTEGER n)
Definition: nmrFnJacobianSolver.h:134
CISSTNETLIB_DOUBLE Tolerance
Definition: nmrFnJacobianSolver.h:110
vctDynamicVector< CISSTNETLIB_DOUBLE > Work
Definition: nmrFnJacobianSolver.h:113
void Allocate(vctDynamicVector< CISSTNETLIB_DOUBLE > &X)
Definition: nmrFnJacobianSolver.h:172
CISSTNETLIB_INTEGER Ldfjac
Definition: nmrFnJacobianSolver.h:109
Definition: nmrCallBack.h:106
#define cmnThrow(a)
Definition: MinimalCmn.h:4
pointer Pointer(index_type index=0)
Definition: vctDynamicVectorBase.h:155
nmrFnJacobianSolver(vctDynamicVector< CISSTNETLIB_DOUBLE > &X)
Definition: nmrFnJacobianSolver.h:146
CISSTNETLIB_INTEGER N
Definition: nmrFnJacobianSolver.h:108