Geogram
Version 1.9.1
A programming library of geometric algorithms
|
The public API of the OpenNL linear solver library. Click the "More..." link below for simple example programs. More...
#include "nl_linkage.h"
#include <stdio.h>
#include <stdint.h>
#include "nl_ext.h"
#include "nl_64.h"
Go to the source code of this file.
Macros | |
#define | NL_VERSION_4_0 1 |
#define | NLAPI |
Solver parameters | |
#define | NL_SOLVER 0x100 |
Symbolic constant for nlSolverParameteri() to specify the used solver. More... | |
#define | NL_NB_VARIABLES 0x101 |
Symbolic constant for nlSolverParameteri() to specify the number of variables. More... | |
#define | NL_LEAST_SQUARES 0x102 |
Symbolic constant for nlSolverParameteri() to specify whether least squares mode is used. More... | |
#define | NL_MAX_ITERATIONS 0x103 |
Symbolic constant for nlSolverParameteri() to specify the maximum number of iterations before the iterative solver is stopped. More... | |
#define | NL_THRESHOLD 0x104 |
Symbolic constant for nlSolverParameterd() to specify the maximum threshold \( \| Ax - b \| / \| b \| \) before the iterative solver is stopped. More... | |
#define | NL_OMEGA 0x105 |
Symbolic constant for nlSolverParameterd() to specify the relaxation parameter \( \omega \in (0,\ldots 2) \) used by the SSOR preconditioner. More... | |
#define | NL_SYMMETRIC 0x106 |
Symbolic constant for nlSolverParameteri() to specify whether the constructed matrix is symmetric. More... | |
#define | NL_USED_ITERATIONS 0x107 |
Symbolic constant for nlGetIntegerv() to obtain the used number of iteration. More... | |
#define | NL_ERROR 0x108 |
Symbolic constant for nlGetDoublev() to obtain the error after nlSolve() is called. More... | |
#define | NL_INNER_ITERATIONS 0x109 |
Symbolic constant for nlSolverParameteri() to specify the number of iterations / number of stored vector in the inner NL_GMRES loop. More... | |
#define | NL_ELAPSED_TIME 0x10a |
Symbolic constant for nlGetDoublev() to obtain the time taken by the latest invocation of nlSolve(), in seconds. More... | |
#define | NL_PRECONDITIONER 0x10b |
Symbolic constant for nlSolverParameteri() to specify the used preconditioner. More... | |
#define | NL_GFLOPS 0x10c |
Symbolic constant for nlGetDoublev() to obtain the average GFlop/Seconds performance counter during the latest invocation of nlSolve(). More... | |
#define | NL_NNZ 0x10d |
Symbolic constant for nlGetIntegerv() to obtain the number of non-zero coefficient in the latest linear system used by nlSolve(). More... | |
#define | NL_NB_SYSTEMS 0x10e |
Symbolic constant for nlSolverParameteri()/nlGetIntegerv() to define or query the number of linear systems to be solved. | |
Solvers | |
#define | NL_SOLVER_DEFAULT 0x000 |
Symbolic constant for nlSolverParameteri() to specify that OpenNL should automatically select a reasonable solver and preconditioner. More... | |
#define | NL_CG 0x200 |
Symbolic constant for nlSolverParameteri() to select the Conjugate Gradient solver. More... | |
#define | NL_BICGSTAB 0x201 |
Symbolic constant for nlSolverParameteri() to select the Conjugate Gradient solver. More... | |
#define | NL_GMRES 0x202 |
Symbolic constant for nlSolverParameteri() to select the GMRES solver. More... | |
Preconditioners | |
#define | NL_PRECOND_NONE 0x000 |
Symbolic constant for nlSolverParameteri() to use no preconditioner. More... | |
#define | NL_PRECOND_JACOBI 0x300 |
Symbolic constant for nlSolverParameteri() to use the Jacobi preconditioner. More... | |
#define | NL_PRECOND_SSOR 0x301 |
Symbolic constant for nlSolverParameteri() to use the SSOR (Successive Over Relaxation) preconditioner. More... | |
#define | NL_PRECOND_USER 0x303 |
Symbolic constant for nlSolverParameteri() to use a user-defined preconditioner. More... | |
Enable / Disable | |
#define | NL_NORMALIZE_ROWS 0x400 |
Symbolic constant for nlEnable() / nlDisable() to enable or disable rows normalization. More... | |
#define | NL_VERBOSE 0x401 |
Symbolic constant for nlEnable() / nlDisable() to enable or disable messages. More... | |
#define | NL_NO_VARIABLES_INDIRECTION 0x402 |
Symbolic constant for nlEnable() / nlDisable() to enable or disable variables indirection. More... | |
Functions | |
Context management | |
NLAPI NLContext NLAPIENTRY | nlNewContext (void) |
Creates a new OpenNL context. More... | |
NLAPI void NLAPIENTRY | nlDeleteContext (NLContext context) |
Destroys an existing OpenNL context. More... | |
NLAPI void NLAPIENTRY | nlMakeCurrent (NLContext context) |
Sets the current OpenNL context. More... | |
NLAPI NLContext NLAPIENTRY | nlGetCurrent (void) |
Gets the current context. More... | |
NLAPI NLboolean NLAPIENTRY | nlInitExtension (const char *extension) |
Initializes an OpenNL extension. More... | |
NLAPI NLboolean NLAPIENTRY | nlExtensionIsInitialized (const char *extension) |
Tests whether an OpenNL extension is initialized. More... | |
NLAPI void NLAPIENTRY | nlInitialize (int argc, char **argv) |
Initializes OpenNL using command line arguments. More... | |
State Get/Set | |
NLAPI void NLAPIENTRY | nlSolverParameterd (NLenum pname, NLdouble param) |
Specifies a floating-point solver parameter. More... | |
NLAPI void NLAPIENTRY | nlSolverParameteri (NLenum pname, NLint param) |
Specifies an integer solver parameter. More... | |
NLAPI void NLAPIENTRY | nlGetBooleanv (NLenum pname, NLboolean *params) |
Gets the value of a boolean parameter. More... | |
NLAPI void NLAPIENTRY | nlGetDoublev (NLenum pname, NLdouble *params) |
Gets the value of a double-precision floating-point parameter. More... | |
NLAPI void NLAPIENTRY | nlGetIntegerv (NLenum pname, NLint *params) |
Gets the value of an integer parameter. More... | |
NLAPI void NLAPIENTRY | nlGetIntegervL (NLenum pname, NLlong *params) |
Gets the value of a 64 bits integer parameter. More... | |
NLAPI void NLAPIENTRY | nlEnable (NLenum pname) |
Sets a boolean parameter to NL_TRUE. More... | |
NLAPI void NLAPIENTRY | nlDisable (NLenum pname) |
Sets a boolean parameter to NL_FALSE. More... | |
NLAPI NLboolean | nlIsEnabled (NLenum pname) |
Tests a boolean parameter. More... | |
Variables | |
NLAPI void NLAPIENTRY | nlSetVariable (NLuint i, NLdouble value) |
Sets the value of a variable. More... | |
NLAPI void NLAPIENTRY | nlMultiSetVariable (NLuint i, NLuint k, NLdouble value) |
Sets the value of a variable when there are several systems to solve. More... | |
NLAPI NLdouble NLAPIENTRY | nlGetVariable (NLuint i) |
Gets the value of a variable. More... | |
NLAPI NLdouble NLAPIENTRY | nlMultiGetVariable (NLuint i, NLuint k) |
Gets the value of a variable when there are several systems to solve. More... | |
NLAPI void NLAPIENTRY | nlLockVariable (NLuint index) |
Locks a variable. More... | |
NLAPI void NLAPIENTRY | nlUnlockVariable (NLuint index) |
Unlocks a variable. More... | |
NLAPI NLboolean NLAPIENTRY | nlVariableIsLocked (NLuint index) |
Tests whether a variable is locked. More... | |
Solve | |
NLAPI NLboolean NLAPIENTRY | nlSolve (void) |
Solves the linear system in the current context. More... | |
NLAPI void NLAPIENTRY | nlUpdateRightHandSide (NLdouble *values) |
Updates the right hand side of the constructed system in one call. More... | |
DataTypes and constants | |
#define | NL_FALSE 0x0 |
Constant for false NLbooleans. More... | |
#define | NL_TRUE 0x1 |
Constant for true NLbooleans. More... | |
typedef unsigned int | NLenum |
A symbolic constant. | |
typedef unsigned char | NLboolean |
A truth value (NL_TRUE or NL_FALSE). More... | |
typedef unsigned int | NLbitfield |
A set of symbolic constants that can be combined with the bitwise or operator. | |
typedef void | NLvoid |
Return type of functions that do not return a value. | |
typedef signed char | NLbyte |
A 1-byte signed integer. | |
typedef short | NLshort |
A 2-bytes signed integer. | |
typedef int32_t | NLint |
A 4-bytes signed integer. | |
typedef unsigned char | NLubyte |
A 1-byte unsigned integer. | |
typedef unsigned short | NLushort |
A 2-bytes unsigned integer. | |
typedef uint32_t | NLuint |
A 4-bytes unsigned integer. | |
typedef int64_t | NLlong |
A 8-bytes signed integer. | |
typedef uint64_t | NLulong |
A 8-bytes unsigned integer. | |
typedef int | NLsizei |
Size of an object, 4-bytes signed integer. | |
typedef float | NLfloat |
A single-precision floating-point number. | |
typedef double | NLdouble |
A double-precision floating-point number. | |
typedef void(* | NLfunc) (void) |
A function pointer. More... | |
typedef void * | NLContext |
An OpenNL context. More... | |
Function pointers | |
#define | NL_FUNC_SOLVER 0x600 |
Symbolic constant for nlSetFunction(), used to replace OpenNL solver with a user-defined routine. More... | |
#define | NL_FUNC_MATRIX 0x601 |
Symbolic constant for nlSetFunction(), used to replace OpenNL matrix-vector product with a user-defined routine. More... | |
#define | NL_FUNC_PRECONDITIONER 0x602 |
Symbolic constant for nlSetFunction(), used to replace OpenNL preconditioner with a user-defined routine. More... | |
#define | NL_FUNC_PROGRESS 0x603 |
Symbolic constant for nlSetFunction(), used to display a progress bar during solve, using a user-defined callback. More... | |
NLAPI void NLAPIENTRY | nlSetFunction (NLenum pname, NLfunc param) |
Sets a function pointer. More... | |
NLAPI void NLAPIENTRY | nlGetFunction (NLenum pname, NLfunc *param) |
Gets a function pointer. More... | |
Begin/End | |
#define | NL_SYSTEM 0x0 |
Symbolic constant for nlBegin() / nlEnd(), to be used to start creating / finalizing a linear system. More... | |
#define | NL_MATRIX 0x1 |
Symbolic constant for nlBegin() / nlEnd(), to be used to start creating / finalizing a matrix. More... | |
#define | NL_ROW 0x2 |
Symbolic constant for nlBegin() / nlEnd(), to be used to start creating / finalizing a row. More... | |
#define | NL_MATRIX_PATTERN 0x3 |
Symbolic constant for nlBegin() / nlEnd(), to be used to start creating / finalizing a row. More... | |
NLAPI void NLAPIENTRY | nlBegin (NLenum primitive) |
Begins a new primitive. More... | |
NLAPI void NLAPIENTRY | nlEnd (NLenum primitive) |
Begins a new primitive. More... | |
NLAPI void NLAPIENTRY | nlSetRowLength (NLuint i, NLuint n) |
Specifies the length of a row of the matrix. More... | |
NLAPI void NLAPIENTRY | nlCoefficient (NLuint i, NLdouble value) |
Appends a coefficient to the current row. More... | |
NLAPI NLulong NLAPIENTRY | nlAddIJCoefficient (NLuint i, NLuint j, NLdouble value) |
Adds a coefficient to the current matrix. More... | |
NLAPI void NLAPIENTRY | nlAddIJCoefficientAt (NLuint i, NLuint j, NLdouble value, NLulong index) |
Adds a coefficient to the current matrix with known index. More... | |
NLAPI void NLAPIENTRY | nlAddIRightHandSide (NLuint i, NLdouble value) |
Adds a coefficient to a component of the right hand side of the equation. More... | |
NLAPI void NLAPIENTRY | nlMultiAddIRightHandSide (NLuint i, NLuint k, NLdouble value) |
Adds a coefficient to a component of the right hand side of the equation. More... | |
NLAPI void NLAPIENTRY | nlRightHandSide (NLdouble value) |
Sets the right-hand side of the current row. More... | |
NLAPI void NLAPIENTRY | nlMultiRightHandSide (NLuint k, NLdouble value) |
Sets the right-hand side of the current row when there are several systems to be solved. More... | |
NLAPI void NLAPIENTRY | nlRowScaling (NLdouble value) |
Sets the row scaling for the next row. More... | |
Buffers | |
#define | NL_VARIABLES_BUFFER 0x1000 |
The symbolic constant for variables buffer. More... | |
NLAPI void NLAPIENTRY | nlBindBuffer (NLenum buffer, NLuint k, void *addr, NLuint stride) |
Specifies a buffer binding to directly map user data to variables instead of using nlGetVariable() / nlSetVariable() More... | |
EigenSolver | |
#define | NL_STIFFNESS_MATRIX 0x3001 |
Constant for nlMatrixMode() | |
#define | NL_MASS_MATRIX 0x3002 |
Constant for nlMatrixMode() | |
#define | NL_NB_EIGENS NL_NB_SYSTEMS |
Symbolic constant for nlEigenSolverParameteri(), number of eigenpairs to compute. | |
#define | NL_EIGEN_MAX_ITERATIONS NL_MAX_ITERATIONS |
Symbolic constant for nlEigenSolverParameteri(), maximum number of iterations. | |
#define | NL_EIGEN_THRESHOLD NL_THRESHOLD |
Symbolic constant for nlEigenSolverParameterd(), convergence threshold. | |
#define | NL_EIGEN_SOLVER 0x2000 |
Symbolic constant for nlEigenSolverParameterd(), name of the eigen solver to be used. | |
#define | NL_EIGEN_SHIFT 0x2001 |
Symbolic constant for nlEigenSolverParameterd(), shift parameter for the shift-invert transform. | |
#define | NL_EIGEN_SHIFT_INVERT 0x2002 |
Symbolic constant for nlEnable() / nlDisable() / nlIsEnabled(), shift-invert spectral transform. | |
NLAPI void NLAPIENTRY | nlMatrixMode (NLenum matrix) |
Specifies to which matrix the subsequent calls to nlBegin(), nlEnd(), nlCoefficient(), nlAddIJCoefficient() will be applied. More... | |
NLAPI void NLAPIENTRY | nlEigenSolverParameterd (NLenum pname, NLdouble val) |
Sets a floating-point parameter of the eigen solver. More... | |
NLAPI void NLAPIENTRY | nlEigenSolverParameteri (NLenum pname, NLint val) |
Sets an integer parameter of the eigen solver. More... | |
NLAPI void NLAPIENTRY | nlEigenSolve (void) |
Calls the eigen solver. | |
NLAPI double NLAPIENTRY | nlGetEigenValue (NLuint i) |
Gets an eigenvalue. More... | |
Logging and messages | |
typedef int(* | NLprintfFunc) (const char *format,...) |
Function pointer type for user printf function. | |
typedef int(* | NLfprintfFunc) (FILE *out, const char *format,...) |
Function pointer type for user fprintf function. | |
NLAPI void NLAPIENTRY | nlPrintfFuncs (NLprintfFunc f1, NLfprintfFunc f2) |
Specifies user functions for printing messages. | |
Low-level access | |
typedef struct NLMatrixStruct * | NLMatrix |
Opaque handle to a matrix. | |
NLAPI NLMatrix NLAPIENTRY | nlGetCurrentMatrix (void) |
Gets the current matrix. More... | |
The public API of the OpenNL linear solver library. Click the "More..." link below for simple example programs.
The purpose of the example programs shown below is to demonstrate OpenNL programs that are as simple as possible. Note that for such small linear systems, the sparse iterative solvers in OpenNL will work, but they are completely inappropriate, one would normally solve the system directly.
Solve \( \left[ \begin{array}{ll} 1 & 2 \\ 3 & 4 \end{array} \right] \left[ \begin{array}{l} x \\ y \end{array} \right] = \left[ \begin{array}{l} 5 \\ 6 \end{array} \right] \)
Reads \( (X,Y) \) coordinates from a file and finds the parameters \( a,b \) of the straight line \( y = ax + b \) that best fits the data points.
As in the previous example, reads \( (X,Y) \) coordinates from a file and finds the parameters \( a,b \) of the straight line \( y = ax + b \) that best fits the data points, but this time subject to the constraint \( a = 1 \).
Before calling nlBegin(NL_SYSTEM), if need be, it is possible to fine-tune additional parameters. See the following examples:
Definition in file nl.h.
#define NL_BICGSTAB 0x201 |
Symbolic constant for nlSolverParameteri() to select the Conjugate Gradient solver.
Usage:
BICGSTAB works for both non-symmetric and symmetric matrices. If the matrix is known to be symmetric, then CG will be more efficient.
#define NL_CG 0x200 |
Symbolic constant for nlSolverParameteri() to select the Conjugate Gradient solver.
Usage:
#define NL_ELAPSED_TIME 0x10a |
Symbolic constant for nlGetDoublev() to obtain the time taken by the latest invocation of nlSolve(), in seconds.
Usage:
#define NL_ERROR 0x108 |
Symbolic constant for nlGetDoublev() to obtain the error after nlSolve() is called.
Gets \( \| Ax - b \| / \| b \| \). Usage:
#define NL_FALSE 0x0 |
#define NL_FUNC_MATRIX 0x601 |
Symbolic constant for nlSetFunction(), used to replace OpenNL matrix-vector product with a user-defined routine.
#define NL_FUNC_PRECONDITIONER 0x602 |
Symbolic constant for nlSetFunction(), used to replace OpenNL preconditioner with a user-defined routine.
#define NL_FUNC_PROGRESS 0x603 |
Symbolic constant for nlSetFunction(), used to display a progress bar during solve, using a user-defined callback.
The user-defined progress callback is called after each iteration, and can be used to update a progress bar.
#define NL_FUNC_SOLVER 0x600 |
Symbolic constant for nlSetFunction(), used to replace OpenNL solver with a user-defined routine.
#define NL_GFLOPS 0x10c |
Symbolic constant for nlGetDoublev() to obtain the average GFlop/Seconds performance counter during the latest invocation of nlSolve().
Usage:
#define NL_GMRES 0x202 |
Symbolic constant for nlSolverParameteri() to select the GMRES solver.
Usage:
GMRES works for both non-symmetric and symmetric matrices. If the matrix is known to be symmetric, then NL_CG will be more efficient. GMRES has an additional internal number of iterations parameters that can be set as follows:
#define NL_INNER_ITERATIONS 0x109 |
Symbolic constant for nlSolverParameteri() to specify the number of iterations / number of stored vector in the inner NL_GMRES loop.
Only relevant if used solver is NL_GMRES. Usage:
#define NL_LEAST_SQUARES 0x102 |
Symbolic constant for nlSolverParameteri() to specify whether least squares mode is used.
Used as follows, before any call to nlBegin():
or
#define NL_MATRIX 0x1 |
#define NL_MATRIX_PATTERN 0x3 |
#define NL_MAX_ITERATIONS 0x103 |
Symbolic constant for nlSolverParameteri() to specify the maximum number of iterations before the iterative solver is stopped.
Usage:
If the solver is left unspecified or is set to NL_SOLVER_DEFAULT, then a reasonable maximum number of iterations is used (5 times the number of free variables).
#define NL_NB_VARIABLES 0x101 |
Symbolic constant for nlSolverParameteri() to specify the number of variables.
Used as follows, before any call to nlBegin():
where nb is the number of variables.
#define NL_NNZ 0x10d |
Symbolic constant for nlGetIntegerv() to obtain the number of non-zero coefficient in the latest linear system used by nlSolve().
Usage:
#define NL_NO_VARIABLES_INDIRECTION 0x402 |
Symbolic constant for nlEnable() / nlDisable() to enable or disable variables indirection.
Usage:
or
#define NL_NORMALIZE_ROWS 0x400 |
Symbolic constant for nlEnable() / nlDisable() to enable or disable rows normalization.
When row normalization is enabled, each time a row is completed with nlEnd(NL_ROW), the coefficients of the current row and its right hand side are divided by the length \( L \) of the current row (and multiplied by the NL_ROW_SCALING \( s \) if one was specified):
\[ \begin{array}{lcl} L & \leftarrow & \sqrt{\sum_{j} a_{i,j}^2} \\ a_{i,j} & \leftarrow & a_{i,j} \times s / L \\ b_i & \leftarrow & b_i \times s / L \end{array} \]
Usage:
or
#define NL_OMEGA 0x105 |
Symbolic constant for nlSolverParameterd() to specify the relaxation parameter \( \omega \in (0,\ldots 2) \) used by the SSOR preconditioner.
Usage:
#define NL_PRECOND_JACOBI 0x300 |
Symbolic constant for nlSolverParameteri() to use the Jacobi preconditioner.
The Jacobi preconditioner corresponds to the inverse of the diagonal elements. Clearly, it requires that the matrix has no zero element on the diagonal. Usage:
#define NL_PRECOND_NONE 0x000 |
Symbolic constant for nlSolverParameteri() to use no preconditioner.
Usage:
#define NL_PRECOND_SSOR 0x301 |
Symbolic constant for nlSolverParameteri() to use the SSOR (Successive Over Relaxation) preconditioner.
Usage:
The SSOR preconditioner can significantly reduce the number of used iterations, but each iteration takes much longer. It has an additional Omega parameter:
#define NL_PRECOND_USER 0x303 |
Symbolic constant for nlSolverParameteri() to use a user-defined preconditioner.
Usage:
The user-defined preconditoner is specified as a function pointer,
#define NL_PRECONDITIONER 0x10b |
Symbolic constant for nlSolverParameteri() to specify the used preconditioner.
Should be one of (NL_PRECOND_NONE, NL_PRECOND_JACOBI, NL_PRECOND_SSOR, NL_PRECOND_USER). If NL_PRECOND_USER is used, then the user-defined preconditioner is specified using nlSetFunction(). Usage:
#define NL_ROW 0x2 |
#define NL_SOLVER 0x100 |
Symbolic constant for nlSolverParameteri() to specify the used solver.
Used as follows, before any call to nlBegin():
where solver is one of (NL_CG, NL_BICGSTAB, NL_GMRES) or one of the extended solvers if supported (NL_xxx_SUPERLU_EXT, NL_CNC_xxx) or NL_SOLVER_DEFAULT to let OpenNL decide and use a reasonable solver.
#define NL_SOLVER_DEFAULT 0x000 |
Symbolic constant for nlSolverParameteri() to specify that OpenNL should automatically select a reasonable solver and preconditioner.
It is the default operating mode of OpenNL. It can also be reset as follows:
It also lets OpenNL choose (hopefully reasonable) values for maximum number of iterations (NL_MAX_ITERATIONS) = 5 times the number of free variables and threshold (NL_THRESHOLD) = 1e-6. It uses the Jacobi-preconditioned conjugate gradient solver (NL_CG and NL_PRECOND_JACOBI) if the matrix is known to be symmetric, and NL_BICGSTAB otherwise.
#define NL_SYMMETRIC 0x106 |
Symbolic constant for nlSolverParameteri() to specify whether the constructed matrix is symmetric.
If the constructed matrix is symmetric, pre-notifying OpenNL before constructing it may improve performance, by allowing more efficient data structures and solvers to be used. Usage:
or
#define NL_SYSTEM 0x0 |
#define NL_THRESHOLD 0x104 |
Symbolic constant for nlSolverParameterd() to specify the maximum threshold \( \| Ax - b \| / \| b \| \) before the iterative solver is stopped.
Usage:
If the solver is left unspecified or is set to NL_SOLVER_DEFAULT, then a reasonable value is used (1e-6).
#define NL_TRUE 0x1 |
#define NL_USED_ITERATIONS 0x107 |
Symbolic constant for nlGetIntegerv() to obtain the used number of iteration.
The solver exits whenever the maximum number of iterations (NL_MAX_ITERATIONS) is reached or whenever \( \| Ax - b \| / \| b \| \) gets smaller than NL_THRESHOLD. Usage:
#define NL_VARIABLES_BUFFER 0x1000 |
The symbolic constant for variables buffer.
Used as an argument of nlEnable() / nlDisable() / nlIsEnabled() and as an argument of nlBindBuffer.
#define NL_VERBOSE 0x401 |
Symbolic constant for nlEnable() / nlDisable() to enable or disable messages.
Usage:
or
typedef unsigned char NLboolean |
typedef void* NLContext |
An OpenNL context.
OpenNL contexts should be considered as opaque ids.
typedef void(* NLfunc) (void) |
A function pointer.
Adds a coefficient to the current matrix.
This function should be called between a nlBegin(NL_MATRIX) / nlEnd(NL_MATRIX) pair (else an assertion failure is triggered). This function should not be called in least squares mode. There should not be any locked variable when using this function.
[in] | i,j | indices |
[in] | value | value to be added to the coefficient |
Adds a coefficient to the current matrix with known index.
Will be faster than nlAddIJCoefficient() if the location (index in the CRS matrix) of the coefficient is known. This function should be called between a nlBegin(NL_MATRIX) / nlEnd(NL_MATRIX) pair (else an assertion failure is triggered). This function should not be called in least squares mode. There should not be any locked variable when using this function.
[in] | i,j | indices |
[in] | value | value to be added to the coefficient |
[in] | index | the index where the coefficient is stored, return by previous call to nlAddIJCoefficient(). If unknown, use nlAddIJCoefficient(). |
Adds a coefficient to a component of the right hand side of the equation.
This function should be called between a nlBegin(NL_MATRIX) / nlEnd(NL_MATRIX) pair (else an assertion failure is triggered). This function should not be called in least squares mode. There should not be any locked variable when using this function.
[in] | i | index of the component |
[in] | value | value to be added to the component |
NLAPI void NLAPIENTRY nlBegin | ( | NLenum | primitive | ) |
Specifies a buffer binding to directly map user data to variables instead of using nlGetVariable() / nlSetVariable()
NL_VARIABLES_BUFFER needs to be previouslyu nlEnabled() else this function has no effect.
[in] | buffer | the type of the buffer, NL_VARIABLES_BUFFER is the only supported value |
[in] | k | the index of the buffer. If type = NL_VARIABLES_BUFFER, this corresponds to the index of the linear system (0 if there is a single linear system). |
[in] | addr | the address of the array to be bound. |
[in] | stride | number of bytes between two consecutive elements. |
Appends a coefficient to the current row.
This function should be called between a nlBegin(NL_ROW) / nlEnd(NL_ROW) pair (else an assertion failure is triggered). The coefficient is either accumumated into the matrix or into the right-hand side according to the locked/unlocked status of the variable.
[in] | i | index of the variable this coefficient is related with |
[in] | value | value of the coefficient |
NLAPI void NLAPIENTRY nlDeleteContext | ( | NLContext | context | ) |
Destroys an existing OpenNL context.
This deallocates all the memory used by the context.
[in,out] | context | the context to be destroyed |
NLAPI void NLAPIENTRY nlDisable | ( | NLenum | pname | ) |
Sets a boolean parameter to NL_FALSE.
[in] | pname | the symbolic name of the parameter |
Sets a floating-point parameter of the eigen solver.
pname | symbolic name of the parameter, one of NL_EIGEN_SHIFT, NL_EIGEN_THRESHOLD. |
Sets an integer parameter of the eigen solver.
pname | symbolic name of the parameter, one of NL_EIGEN_SOLVER, NL_NB_EIGENS, NL_NB_VARIABLES, NL_EIGEN_MAX_ITERATIONS, NL_SYMMETRIC. |
NLAPI void NLAPIENTRY nlEnable | ( | NLenum | pname | ) |
Sets a boolean parameter to NL_TRUE.
[in] | pname | the symbolic name of the parameter |
NLAPI void NLAPIENTRY nlEnd | ( | NLenum | primitive | ) |
Begins a new primitive.
nlBegin()/nlEnd() calls should be properly nested, as follows (otherwise an assertion failure is triggered):
[in] | primitive | one of NL_SYSTEM, NL_MATRIX, NL_ROW |
NLAPI NLboolean NLAPIENTRY nlExtensionIsInitialized | ( | const char * | extension | ) |
Tests whether an OpenNL extension is initialized.
NL_TRUE | if the extension is initialized. |
NL_FALSE | otherwise |
Gets the value of a boolean parameter.
[in] | pname | the symbolic name of the parameter |
[out] | params | a pointer to the obtained parameter value |
NLAPI NLContext NLAPIENTRY nlGetCurrent | ( | void | ) |
Gets the current context.
NLAPI NLMatrix NLAPIENTRY nlGetCurrentMatrix | ( | void | ) |
Gets the current matrix.
for advanced low-level matrix manipulation
Gets the value of a double-precision floating-point parameter.
[in] | pname | the symbolic name of the parameter |
[out] | params | a pointer to the obtained parameter value |
NLAPI double NLAPIENTRY nlGetEigenValue | ( | NLuint | i | ) |
Gets an eigenvalue.
i | index of the eigenvalue. |
i
th eigenvalue. Gets a function pointer.
[in] | pname | symbolic name of the function |
[out] | param | the function pointer |
Gets the value of an integer parameter.
[in] | pname | the symbolic name of the parameter |
[out] | params | a pointer to the obtained parameter value |
Gets the value of a 64 bits integer parameter.
[in] | pname | the symbolic name of the parameter |
[out] | params | a pointer to the obtained parameter value |
Gets the value of a variable.
[in] | i | index of the variable, between 0 and nlGetInteger(NL_NB_VARIABLES)-1 |
NLAPI NLboolean NLAPIENTRY nlInitExtension | ( | const char * | extension | ) |
Initializes an OpenNL extension.
OpenNL may be compiled with several extensions, that provide alternative solvers, such as SuperLU (sparse direct solver) and CNC (iterative solver on the GPU). This function tests whether an extension is supported, and initializes what needs to be initialized in the extention.
NL_TRUE | if the extension is supported and could be successfully initialized |
NL_FALSE | otherwise |
NLAPI void NLAPIENTRY nlInitialize | ( | int | argc, |
char ** | argv | ||
) |
Initializes OpenNL using command line arguments.
Command line arguments of the form nl:<extension>=true|false are parsed and taken into account. Calling this function is not mandatory.
Tests a boolean parameter.
[in] | pname | the symbolic name of the parameter |
NLAPI void NLAPIENTRY nlLockVariable | ( | NLuint | index | ) |
Locks a variable.
Locked variables are no-longer computed by OpenNL, their initial value, specified by nlSetVariable(), is used as follows:
[in] | index | index of the variable, between 0 and nlGetInteger(NL_NB_VARIABLES)-1 |
NLAPI void NLAPIENTRY nlMakeCurrent | ( | NLContext | context | ) |
Sets the current OpenNL context.
If several OpenNL contexts need to be used simultaneously, this function can be used to redirect all OpenNL calls to a specific context.
NLAPI void NLAPIENTRY nlMatrixMode | ( | NLenum | matrix | ) |
Specifies to which matrix the subsequent calls to nlBegin(), nlEnd(), nlCoefficient(), nlAddIJCoefficient() will be applied.
[in] | matrix | one of NL_STIFFNESS_MATRIX (default), NL_MASS_MATRIX |
Calling nlMatrixMode() resets the current row to 0.
Adds a coefficient to a component of the right hand side of the equation.
This function should be called between a nlBegin(NL_MATRIX) / nlEnd(NL_MATRIX) pair (else an assertion failure is triggered). This function should not be called in least squares mode. There should not be any locked variable when using this function.
[in] | i | index of the component |
[in] | k | index of the system |
[in] | value | value to be added to the component |
Gets the value of a variable when there are several systems to solve.
[in] | i | index of the variable, between 0 and nlGetInteger(NL_NB_VARIABLES)-1 |
[in] | k | index of the system, between 0 and nlGetInteger(NL_NB_SYSTEMS)-1 |
Sets the right-hand side of the current row when there are several systems to be solved.
[in] | k | index of the system, in 0..nlGetInt(NL_NB_SYSTEMS)-1 |
[in] | value | the coefficient |
Sets the value of a variable when there are several systems to solve.
[in] | i | index of the variable, between 0 and nlGetInteger(NL_NB_VARIABLES)-1 |
[in] | k | index of the system, between 0 and nlGetInteger(NL_NB_SYSTEMS)-1 |
[in] | value | value of the variable |
NLAPI NLContext NLAPIENTRY nlNewContext | ( | void | ) |
Creates a new OpenNL context.
Must be called before any other OpenNL function. On exit, the newly created context is the current OpenNL context. Several OpenNL context may coexist. All OpenNL calls are forwarded to the current OpenNL context. Use nlMakeCurrent() to switch between multiple OpenNL contexts. Any created context needs to be destroyed before the end of the program using nlDeleteContext().
NLAPI void NLAPIENTRY nlRightHandSide | ( | NLdouble | value | ) |
Sets the right-hand side of the current row.
\[ \sum_j a_{i,j} x_j = b_i \]
\[ \left( \sum_j a_{i,j} x_j - b_i \right)^2 \]
Usage:[in] | value | value to be accumulated into the right hand side. |
NLAPI void NLAPIENTRY nlRowScaling | ( | NLdouble | value | ) |
Sets the row scaling for the next row.
\[ \begin{array}{lcl} a_{i,j} & \leftarrow & a_{i,j} \times s \\ b_i & \leftarrow & b_i \times s \end{array} \]
\[ \begin{array}{lcl} L & \leftarrow & \sqrt{\sum_{j} a_{i,j}^2} \\ a_{i,j} & \leftarrow & a_{i,j} \times s / L\\ b_i & \leftarrow & b_i \times s / L \end{array} \]
[in] | value | the row scaling. |
Sets a function pointer.
[in] | pname | symbolic name of the function, one of (NL_FUNC_MATRIX, NL_FUNC_PRECONDITIONER, NL_FUNC_PROGRESS) |
[in] | param | the function pointer |
Specifies the length of a row of the matrix.
Should be called between nlBegin(NL_MATRIX_PATTERN) and nlEnd(NL_MATRIX_PATTERN).
[in] | i | the index of the row. |
[in] | n | the length of the row. |
Sets the value of a variable.
[in] | i | index of the variable, between 0 and nlGetInteger(NL_NB_VARIABLES)-1 |
[in] | value | value of the variable |
NLAPI NLboolean NLAPIENTRY nlSolve | ( | void | ) |
Solves the linear system in the current context.
This function should be called after nlEnd(NL_SYSTEM), else an assertion failure is triggered. Once the function is called, client code may get the value of the computed variables using nlGetVariable().
Specifies a floating-point solver parameter.
This function should be called in the initial state of OpenNL, before any nlBegin() / nlEnd() call.
[in] | pname | the symbolic name of the parameter, one of (NL_THRESHOLD, NL_OMEGA). |
[in] | param | the double-precision floating-point value of the parameter.
|
Specifies an integer solver parameter.
This function should be called in the initial state of OpenNL, before any nlBegin() / nlEnd() call.
[in] | pname | the symbolic name of the parameter, one of (NL_SOLVER, NL_NB_VARIABLES, NL_LEAST_SQUARES, NL_MAX_ITERATIONS, NL_SYMMETRIC, NL_INNER_ITERATIONS, NL_PRECONDITIONER). |
[in] | param | the integer value of the parameter.
|
NLAPI void NLAPIENTRY nlUnlockVariable | ( | NLuint | index | ) |
Unlocks a variable.
Locked variables are no-longer computed by OpenNL, their initial value, specified by nlSetVariable(), is used as follows:
[in] | index | index of the variable, between 0 and nlGetInteger(NL_NB_VARIABLES)-1 |
NLAPI void NLAPIENTRY nlUpdateRightHandSide | ( | NLdouble * | values | ) |
Updates the right hand side of the constructed system in one call.
[in] | values | a pointer to an array of N doubles, where N corresponds to the number of not locked variables. |
If the current state is solved, it resets the current state to constructed. This function cannot be called if NL_NB_SYSTEMS is different from 1.
Tests whether a variable is locked.
Locked variables are no-longer computed by OpenNL, their initial value, specified by nlSetVariable(), is used as follows:
[in] | index | index of the variable, between 0 and nlGetInteger(NL_NB_VARIABLES)-1 |