nimterop / nimterop

Nimterop is a Nim package that aims to make C/C++ interop seamless
MIT License
357 stars 39 forks source link

cImporting dynlib doesn't add #include header in generated C code #134

Closed HugoGranstrom closed 4 years ago

HugoGranstrom commented 5 years ago

When I'm just cImport:ing a header it gets included in the generated C code like this:

# in Nim code
cImport("include/header1.h")
// in C code
#include "path to header1.h"

But when I give it a dynamic library it doesn't include it in the generated C code:

# in Nim code
cImport("include/header1.h")
cImport("include/header2.h", "dynlib2")
// generated C 
#include "path to header1.h"
// expected C
#include "path to header1.h"
#include "path to header2.h"

This is troublesome if header2.h contains type definitions that is needed for the program. I solved this by moving the type definitions to a separate header file but it would be nice if Nimterop did this automagically in some way for me. Is there a reason why the header file doesn't get included or is it me who are just missing something 😅

genotrance commented 4 years ago

This is blocked due to a Nim bug. That being said, can you share what the generated wrapper looks like (with the issue)?

HugoGranstrom commented 4 years ago

cc @mantielero

HugoGranstrom commented 4 years ago

I won't have access to my computer until Friday 🤔😅 @mantielero do you have a error-prone version ready?

mantielero commented 4 years ago

I think so

mantielero commented 4 years ago

In the forum and some code.

genotrance commented 4 years ago

I saw both but neither had the cImport output. I need to see what nimterop is generating.

mantielero commented 4 years ago

You mean this:

{.passC: "-I/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include".}

{.passC: "-I/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/lib64".}
# Importing /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_config.h
# Generated at 2019-07-29T21:21:32+02:00
# Command line:
#   /home/jose/.nimble/pkgs/nimterop-#head/nimterop/toast --preprocess --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/lib64 --pnim --nim:/home/jose/.choosenim/toolchains/nim-0.20.2/bin/nim --pluginSourcePath=/tmp/nimterop_170946992310022160.nim /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_config.h

{.hint[ConvFromXtoItselfNotNeeded]: off.}

import nimterop/types

const
  headersundials_config {.used.} = "/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_config.h"

#  -----------------------------------------------------------------
#  * Programmer(s): Aaron Collier and Radu Serban @ LLNL
#  * -----------------------------------------------------------------
#  * LLNS/SMU Copyright Start
#  * Copyright (c) 2002-2018, Southern Methodist University and
#  * Lawrence Livermore National Security
#  *
#  * This work was performed under the auspices of the U.S. Department
#  * of Energy by Southern Methodist University and Lawrence Livermore
#  * National Laboratory under Contract DE-AC52-07NA27344.
#  * Produced at Southern Methodist University and the Lawrence
#  * Livermore National Laboratory.
#  *
#  * All rights reserved.
#  * For details, see the LICENSE file.
#  * LLNS/SMU Copyright End
#  * -----------------------------------------------------------------
#  * SUNDIALS configuration header file
#  * -----------------------------------------------------------------
#  Define SUNDIALS version numbers
  SUNDIALS_VERSION_MAJOR* = 5
  SUNDIALS_VERSION_MINOR* = 0
  SUNDIALS_VERSION_PATCH* = 0

#  FCMIX: Define Fortran name-mangling macro for C identifiers.
#  * Depending on the inferred scheme, one of the following six
#  * macros will be defined:
#  *     #define SUNDIALS_F77_FUNC(name,NAME) name
#  *     #define SUNDIALS_F77_FUNC(name,NAME) name ## _
#  *     #define SUNDIALS_F77_FUNC(name,NAME) name ## __
#  *     #define SUNDIALS_F77_FUNC(name,NAME) NAME
#  *     #define SUNDIALS_F77_FUNC(name,NAME) NAME ## _
#  *     #define SUNDIALS_F77_FUNC(name,NAME) NAME ## __
#
#  FCMIX: Define Fortran name-mangling macro for C identifiers
#  *        which contain underscores.
#
#  Define precision of SUNDIALS data type 'realtype'
#  * Depending on the precision level, one of the following
#  * three macros will be defined:
#  *     #define SUNDIALS_SINGLE_PRECISION 1
#  *     #define SUNDIALS_DOUBLE_PRECISION 1
#  *     #define SUNDIALS_EXTENDED_PRECISION 1
#
  SUNDIALS_DOUBLE_PRECISION* = 1

#  Define type of vector indices in SUNDIALS 'sunindextype'.
#  * Depending on user choice of index type, one of the following
#  * two macros will be defined:
#  *     #define SUNDIALS_INT64_T 1
#  *     #define SUNDIALS_INT32_T 1
#
  SUNDIALS_INT64_T* = 1

#  Define the type of vector indices in SUNDIALS 'sunindextype'.
#  * The macro will be defined with a type of the appropriate size.
#
#  Use generic math functions
#  * If it was decided that generic math functions can be used, then
#  *     #define SUNDIALS_USE_GENERIC_MATH
#
#  Use POSIX timers if available.
#  *     #define SUNDIALS_HAVE_POSIX_TIMERS
#
#  Blas/Lapack available
#  * If working libraries for Blas/lapack support were found, then
#  *     #define SUNDIALS_BLAS_LAPACK
#
#  SUPERLUMT available
#  * If working libraries for SUPERLUMT support were found, then
#  *     #define SUNDIALS_SUPERLUMT
#
#  SUPERLUDIST available
#  * If working libraries for SUPERLUDIST support were found, then
#  *    #define SUNDIALS_SUPERLUDIST
#
#  KLU available
#  * If working libraries for KLU support were found, then
#  *     #define SUNDIALS_KLU
#
#  Trilinos available
#  * If working libraries for Trilinos support were found, then
#  *     #define SUNDIALS_TRILINOS
#
#  Trilinos with MPI is available, then
#   *    #define SUNDIALS_TRILINOS_HAVE_MPI
#
#  Set if SUNDIALS is built with MPI support.
#  *
#
#  FNVECTOR: Allow user to specify different MPI communicator
#  * If it was found that the MPI implementation supports MPI_Comm_f2c, then
#  *      #define SUNDIALS_MPI_COMM_F2C 1
#  * otherwise
#  *      #define SUNDIALS_MPI_COMM_F2C 0
#
  SUNDIALS_MPI_COMM_F2C* = 0

{.pragma: impsundials_config, importc, header: headersundials_config.}
{.pragma: impsundials_configC, impsundials_config, cdecl.}

# Importing /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_types.h
# Generated at 2019-07-29T21:21:32+02:00
# Command line:
#   /home/jose/.nimble/pkgs/nimterop-#head/nimterop/toast --preprocess --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/lib64 --pnim --nim:/home/jose/.choosenim/toolchains/nim-0.20.2/bin/nim --pluginSourcePath=/tmp/nimterop_170946992310022160.nim /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_types.h

{.hint[ConvFromXtoItselfNotNeeded]: off.}

import nimterop/types

const
  headersundials_types {.used.} = "/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_types.h"

#
#  *------------------------------------------------------------------
#  * Type : booleantype
#  *------------------------------------------------------------------
#  * Constants : SUNFALSE and SUNTRUE
#  *------------------------------------------------------------------
#  * ANSI C does not have a built-in boolean data type. Below is the
#  * definition for a new type called booleantype. The advantage of
#  * using the name booleantype (instead of int) is an increase in
#  * code readability. It also allows the programmer to make a
#  * distinction between int and boolean data. Variables of type
#  * booleantype are intended to have only the two values SUNFALSE and
#  * SUNTRUE which are defined below to be equal to 0 and 1,
#  * respectively.
#  *------------------------------------------------------------------
#
  SUNFALSE* = 0
  SUNTRUE* = 1

{.pragma: impsundials_types, importc, header: headersundials_types.}
{.pragma: impsundials_typesC, impsundials_types, cdecl.}

type

#  -----------------------------------------------------------------
#  * Programmer(s): Scott Cohen, Alan Hindmarsh, Radu Serban,
#  *                Aaron Collier, and Slaven Peles @ LLNL
#  * -----------------------------------------------------------------
#  * SUNDIALS Copyright Start
#  * Copyright (c) 2002-2019, Lawrence Livermore National Security
#  * and Southern Methodist University.
#  * All rights reserved.
#  *
#  * See the top-level LICENSE and NOTICE files for details.
#  *
#  * SPDX-License-Identifier: BSD-3-Clause
#  * SUNDIALS Copyright End
#  * -----------------------------------------------------------------
#  * This header file exports three types: realtype, sunindextype and
#  * booleantype, as well as the constants SUNTRUE and SUNFALSE.
#  *
#  * Users should include the header file sundials_types.h in every
#  * program file and use the exported name realtype instead of
#  * float, double or long double.
#  *
#  * The constants SUNDIALS_SINGLE_PRECISION, SUNDIALS_DOUBLE_PRECISION
#  * and SUNDIALS_LONG_DOUBLE_PRECISION indicate the underlying data
#  * type of realtype.
#  *
#  * The legal types for realtype are float, double and long double.
#  *
#  * The constants SUNDIALS_INT64_T and SUNDIALS_INT32_T indicate
#  * the underlying data type of sunindextype -- the integer data type
#  * used for vector and matrix indices.
#  *
#  * Data types are set at the configuration stage.
#  *
#  * The macro RCONST gives the user a convenient way to define
#  * real-valued literal constants. To use the constant 1.0, for example,
#  * the user should write the following:
#  *
#  *   #define ONE RCONST(1.0)
#  *
#  * If realtype is defined as a double, then RCONST(1.0) expands
#  * to 1.0. If realtype is defined as a float, then RCONST(1.0)
#  * expands to 1.0F. If realtype is defined as a long double,
#  * then RCONST(1.0) expands to 1.0L. There is never a need to
#  * explicitly cast 1.0 to (realtype). The macro can be used for
#  * literal constants only. It cannot be used for expressions.
#  * -----------------------------------------------------------------
#
#  *------------------------------------------------------------------
#  * Macro _SUNDIALS_STRUCT_
#  * The _SUNDIALS_STRUCT_ macro is defined as a `struct` unless
#  * generating the SWIG interfaces - in that case it is defined as
#  * nothing. This is needed to work around a bug in SWIG which prevents
#  * it from properly parsing our generic module structures.
#  *------------------------------------------------------------------
#
#
#  *------------------------------------------------------------------
#  * Type realtype
#  * Macro RCONST
#  * Constants BIG_REAL, SMALL_REAL, and UNIT_ROUNDOFF
#  *------------------------------------------------------------------
#
  realtype* {.impsundials_types.} = cdouble

#
#  *------------------------------------------------------------------
#  * Type : sunindextype
#  *------------------------------------------------------------------
#  * Defines integer type to be used for vector and matrix indices.
#  * User can build sundials to use 32- or 64-bit signed integers.
#  * If compiler does not support portable data types, the SUNDIALS
#  * CMake build system tries to find a type of the desired size.
#  *------------------------------------------------------------------
#
  sunindextype* {.impsundials_types.} = int64

# Importing /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_math.h
# Generated at 2019-07-29T21:21:32+02:00
# Command line:
#   /home/jose/.nimble/pkgs/nimterop-#head/nimterop/toast --preprocess --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/lib64 --pnim --nim:/home/jose/.choosenim/toolchains/nim-0.20.2/bin/nim --pluginSourcePath=/tmp/nimterop_170946992310022160.nim /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_math.h

{.hint[ConvFromXtoItselfNotNeeded]: off.}

import nimterop/types

const
  headersundials_math {.used.} = "/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_math.h"

{.pragma: impsundials_math, importc, header: headersundials_math.}
{.pragma: impsundials_mathC, impsundials_math, cdecl.}

#
#  * -----------------------------------------------------------------
#  * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh and
#  *                Aaron Collier @ LLNL
#  * -----------------------------------------------------------------
#  * SUNDIALS Copyright Start
#  * Copyright (c) 2002-2019, Lawrence Livermore National Security
#  * and Southern Methodist University.
#  * All rights reserved.
#  *
#  * See the top-level LICENSE and NOTICE files for details.
#  *
#  * SPDX-License-Identifier: BSD-3-Clause
#  * SUNDIALS Copyright End
#  * -----------------------------------------------------------------
#  * This is the header file for a simple C-language math library. The
#  * routines listed here work with the type realtype as defined in
#  * the header file sundials_types.h.
#  * -----------------------------------------------------------------
#
#
#  * -----------------------------------------------------------------
#  * Macros
#  * -----------------------------------------------------------------
#  * MIN(A,B) returns the minimum of A and B
#  *
#  * MAX(A,B) returns the maximum of A and B
#  *
#  * SQR(A) returns A^2
#  *
#  * SUNRsqrt calls the appropriate version of sqrt
#  *
#  * SUNRabs calls the appropriate version of abs
#  *
#  * SUNRexp calls the appropriate version of exp
#  * -----------------------------------------------------------------
#
#
#  * -----------------------------------------------------------------
#  * Function : SUNRsqrt
#  * -----------------------------------------------------------------
#  * Usage : realtype sqrt_x;
#  *         sqrt_x = SUNRsqrt(x);
#  * -----------------------------------------------------------------
#  * SUNRsqrt(x) returns the square root of x. If x < ZERO, then
#  * SUNRsqrt returns ZERO.
#  * -----------------------------------------------------------------
#
#
#  * -----------------------------------------------------------------
#  * Function : SUNRabs
#  * -----------------------------------------------------------------
#  * Usage : realtype abs_x;
#  *         abs_x = SUNRabs(x);
#  * -----------------------------------------------------------------
#  * SUNRabs(x) returns the absolute value of x.
#  * -----------------------------------------------------------------
#
#
#  * -----------------------------------------------------------------
#  * Function : SUNRexp
#  * -----------------------------------------------------------------
#  * Usage : realtype exp_x;
#  *         exp_x = SUNRexp(x);
#  * -----------------------------------------------------------------
#  * SUNRexp(x) returns e^x (base-e exponential function).
#  * -----------------------------------------------------------------
#
#
#  * -----------------------------------------------------------------
#  * Function : SUNRpowerI
#  * -----------------------------------------------------------------
#  * Usage : int exponent;
#  *         realtype base, ans;
#  *         ans = SUNRpowerI(base,exponent);
#  * -----------------------------------------------------------------
#  * SUNRpowerI returns the value of base^exponent, where base is of type
#  * realtype and exponent is of type int.
#  * -----------------------------------------------------------------
#
proc SUNRpowerI*(base: realtype, exponent: cint): realtype {.impsundials_mathC.}

#
#  * -----------------------------------------------------------------
#  * Function : SUNRpowerR
#  * -----------------------------------------------------------------
#  * Usage : realtype base, exponent, ans;
#  *         ans = SUNRpowerR(base,exponent);
#  * -----------------------------------------------------------------
#  * SUNRpowerR returns the value of base^exponent, where both base and
#  * exponent are of type realtype. If base < ZERO, then SUNRpowerR
#  * returns ZERO.
#  * -----------------------------------------------------------------
#
proc SUNRpowerR*(base: realtype, exponent: realtype): realtype {.impsundials_mathC.}

# Importing /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_nvector.h
# Generated at 2019-07-29T21:21:32+02:00
# Command line:
#   /home/jose/.nimble/pkgs/nimterop-#head/nimterop/toast --preprocess --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/lib64 --pnim --nim:/home/jose/.choosenim/toolchains/nim-0.20.2/bin/nim --pluginSourcePath=/tmp/nimterop_170946992310022160.nim /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_nvector.h

{.hint[ConvFromXtoItselfNotNeeded]: off.}

import nimterop/types

#  -----------------------------------------------------------------
#  * Programmer(s): Radu Serban and Aaron Collier @ LLNL
#  * -----------------------------------------------------------------
#  * SUNDIALS Copyright Start
#  * Copyright (c) 2002-2019, Lawrence Livermore National Security
#  * and Southern Methodist University.
#  * All rights reserved.
#  *
#  * See the top-level LICENSE and NOTICE files for details.
#  *
#  * SPDX-License-Identifier: BSD-3-Clause
#  * SUNDIALS Copyright End
#  * -----------------------------------------------------------------
#  * This is the header file for a generic NVECTOR package.
#  * It defines the N_Vector structure (_generic_N_Vector) which
#  * contains the following fields:
#  *   - an implementation-dependent 'content' field which contains
#  *     the description and actual data of the vector
#  *   - an 'ops' filed which contains a structure listing operations
#  *     acting on such vectors
#  * -----------------------------------------------------------------
#  * This header file contains:
#  *   - enumeration constants for all SUNDIALS-defined vector types,
#  *     as well as a generic type for user-supplied vector types,
#  *   - type declarations for the _generic_N_Vector and
#  *     _generic_N_Vector_Ops structures, as well as references to
#  *     pointers to such structures (N_Vector), and
#  *   - prototypes for the vector functions which operate on
#  *     N_Vector objects.
#  * -----------------------------------------------------------------
#  * At a minimum, a particular implementation of an NVECTOR must
#  * do the following:
#  *   - specify the 'content' field of N_Vector,
#  *   - implement the operations on those N_Vector objects,
#  *   - provide a constructor routine for new N_Vector objects
#  *
#  * Additionally, an NVECTOR implementation may provide the following:
#  *   - macros to access the underlying N_Vector data
#  *   - a constructor for an array of N_Vectors
#  *   - a constructor for an empty N_Vector (i.e., a new N_Vector with
#  *     a NULL data pointer).
#  *   - a routine to print the content of an N_Vector
#  * -----------------------------------------------------------------
#  -----------------------------------------------------------------
#  * Implemented N_Vector types
#  * -----------------------------------------------------------------
defineEnum(N_Vector_ID)

const
  headersundials_nvector {.used.} = "/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_nvector.h"
  SUNDIALS_NVEC_SERIAL* = 0.N_Vector_ID
  SUNDIALS_NVEC_PARALLEL* = 1.N_Vector_ID
  SUNDIALS_NVEC_OPENMP* = 2.N_Vector_ID
  SUNDIALS_NVEC_PTHREADS* = 3.N_Vector_ID
  SUNDIALS_NVEC_PARHYP* = 4.N_Vector_ID
  SUNDIALS_NVEC_PETSC* = 5.N_Vector_ID
  SUNDIALS_NVEC_CUDA* = 6.N_Vector_ID
  SUNDIALS_NVEC_RAJA* = 7.N_Vector_ID
  SUNDIALS_NVEC_OPENMPDEV* = 8.N_Vector_ID
  SUNDIALS_NVEC_TRILINOS* = 9.N_Vector_ID
  SUNDIALS_NVEC_MANYVECTOR* = 10.N_Vector_ID
  SUNDIALS_NVEC_MPIMANYVECTOR* = 11.N_Vector_ID
  SUNDIALS_NVEC_MPIPLUSX* = 12.N_Vector_ID
  SUNDIALS_NVEC_CUSTOM* = 13.N_Vector_ID

{.pragma: impsundials_nvector, importc, header: headersundials_nvector.}
{.pragma: impsundials_nvectorC, impsundials_nvector, cdecl.}

type

#  -----------------------------------------------------------------
#  * Generic definition of N_Vector
#  * -----------------------------------------------------------------
#  Forward reference for pointer to N_Vector_Ops object
  N_Vector_Ops* {.impsundials_nvector.} = ptr generic_N_Vector_Ops

#  Forward reference for pointer to N_Vector object
  N_Vector* {.impsundials_nvector.} = ptr generic_N_Vector

#  Define array of N_Vectors
  N_Vector_S* {.impsundials_nvector.} = ptr N_Vector

#  Structure containing function pointers to vector operations
  generic_N_Vector_Ops* {.importc: "struct _generic_N_Vector_Ops", header: headersundials_nvector, bycopy.} = object
    nvgetvectorid*: proc(a1: N_Vector): N_Vector_ID {.cdecl.}
    nvclone*: proc(a1: N_Vector): N_Vector {.cdecl.}
    nvcloneempty*: proc(a1: N_Vector): N_Vector {.cdecl.}
    nvdestroy*: proc(a1: N_Vector) {.cdecl.}
    nvspace*: proc(a1: N_Vector, a2: ptr sunindextype, a3: ptr sunindextype) {.cdecl.}
    nvgetarraypointer*: proc(a1: N_Vector): ptr realtype {.cdecl.}
    nvsetarraypointer*: proc(a1: ptr realtype, a2: N_Vector) {.cdecl.}
    nvgetcommunicator*: proc(a1: N_Vector): pointer {.cdecl.}
    nvgetlength*: proc(a1: N_Vector): sunindextype {.cdecl.}
    nvlinearsum*: proc(a1: realtype, a2: N_Vector, a3: realtype, a4: N_Vector, a5: N_Vector) {.cdecl.}
    nvconst*: proc(a1: realtype, a2: N_Vector) {.cdecl.}
    nvprod*: proc(a1: N_Vector, a2: N_Vector, a3: N_Vector) {.cdecl.}
    nvdiv*: proc(a1: N_Vector, a2: N_Vector, a3: N_Vector) {.cdecl.}
    nvscale*: proc(a1: realtype, a2: N_Vector, a3: N_Vector) {.cdecl.}
    nvabs*: proc(a1: N_Vector, a2: N_Vector) {.cdecl.}
    nvinv*: proc(a1: N_Vector, a2: N_Vector) {.cdecl.}
    nvaddconst*: proc(a1: N_Vector, a2: realtype, a3: N_Vector) {.cdecl.}
    nvdotprod*: proc(a1: N_Vector, a2: N_Vector): realtype {.cdecl.}
    nvmaxnorm*: proc(a1: N_Vector): realtype {.cdecl.}
    nvwrmsnorm*: proc(a1: N_Vector, a2: N_Vector): realtype {.cdecl.}
    nvwrmsnormmask*: proc(a1: N_Vector, a2: N_Vector, a3: N_Vector): realtype {.cdecl.}
    nvmin*: proc(a1: N_Vector): realtype {.cdecl.}
    nvwl2norm*: proc(a1: N_Vector, a2: N_Vector): realtype {.cdecl.}
    nvl1norm*: proc(a1: N_Vector): realtype {.cdecl.}
    nvcompare*: proc(a1: realtype, a2: N_Vector, a3: N_Vector) {.cdecl.}
    nvinvtest*: proc(a1: N_Vector, a2: N_Vector): cint {.cdecl.}
    nvconstrmask*: proc(a1: N_Vector, a2: N_Vector, a3: N_Vector): cint {.cdecl.}
    nvminquotient*: proc(a1: N_Vector, a2: N_Vector): realtype {.cdecl.}
    nvlinearcombination*: proc(a1: cint, a2: ptr realtype, a3: ptr N_Vector, a4: N_Vector): cint {.cdecl.}
    nvscaleaddmulti*: proc(a1: cint, a2: ptr realtype, a3: N_Vector, a4: ptr N_Vector, a5: ptr N_Vector): cint {.cdecl.}
    nvdotprodmulti*: proc(a1: cint, a2: N_Vector, a3: ptr N_Vector, a4: ptr realtype): cint {.cdecl.}
    nvlinearsumvectorarray*: proc(a1: cint, a2: realtype, a3: ptr N_Vector, a4: realtype, a5: ptr N_Vector, a6: ptr N_Vector): cint {.cdecl.}
    nvscalevectorarray*: proc(a1: cint, a2: ptr realtype, a3: ptr N_Vector, a4: ptr N_Vector): cint {.cdecl.}
    nvconstvectorarray*: proc(a1: cint, a2: realtype, a3: ptr N_Vector): cint {.cdecl.}
    nvwrmsnormvectorarray*: proc(a1: cint, a2: ptr N_Vector, a3: ptr N_Vector, a4: ptr realtype): cint {.cdecl.}
    nvwrmsnormmaskvectorarray*: proc(a1: cint, a2: ptr N_Vector, a3: ptr N_Vector, a4: N_Vector, a5: ptr realtype): cint {.cdecl.}
    nvscaleaddmultivectorarray*: proc(a1: cint, a2: cint, a3: ptr realtype, a4: ptr N_Vector, a5: ptr ptr N_Vector, a6: ptr ptr N_Vector): cint {.cdecl.}
    nvlinearcombinationvectorarray*: proc(a1: cint, a2: cint, a3: ptr realtype, a4: ptr ptr N_Vector, a5: ptr N_Vector): cint {.cdecl.}
    nvdotprodlocal*: proc(a1: N_Vector, a2: N_Vector): realtype {.cdecl.}
    nvmaxnormlocal*: proc(a1: N_Vector): realtype {.cdecl.}
    nvminlocal*: proc(a1: N_Vector): realtype {.cdecl.}
    nvl1normlocal*: proc(a1: N_Vector): realtype {.cdecl.}
    nvinvtestlocal*: proc(a1: N_Vector, a2: N_Vector): cint {.cdecl.}
    nvconstrmasklocal*: proc(a1: N_Vector, a2: N_Vector, a3: N_Vector): cint {.cdecl.}
    nvminquotientlocal*: proc(a1: N_Vector, a2: N_Vector): realtype {.cdecl.}
    nvwsqrsumlocal*: proc(a1: N_Vector, a2: N_Vector): realtype {.cdecl.}
    nvwsqrsummasklocal*: proc(a1: N_Vector, a2: N_Vector, a3: N_Vector): realtype {.cdecl.}

#  A vector is a structure with an implementation-dependent
#    'content' field, and a pointer to a structure of vector
#    operations corresponding to that implementation.
  generic_N_Vector* {.importc: "struct _generic_N_Vector", header: headersundials_nvector, bycopy.} = object
    content*: pointer
    ops*: N_Vector_Ops

#  -----------------------------------------------------------------
#  * Functions exported by NVECTOR module
#  * -----------------------------------------------------------------
proc N_VNewEmpty*(): N_Vector {.impsundials_nvectorC.}
proc N_VFreeEmpty*(v: N_Vector) {.impsundials_nvectorC.}
proc N_VCopyOps*(w: N_Vector, v: N_Vector): cint {.impsundials_nvectorC.}
proc N_VGetVectorID*(w: N_Vector): N_Vector_ID {.impsundials_nvectorC.}
proc N_VClone*(w: N_Vector): N_Vector {.impsundials_nvectorC.}
proc N_VCloneEmpty*(w: N_Vector): N_Vector {.impsundials_nvectorC.}
proc N_VDestroy*(v: N_Vector) {.impsundials_nvectorC.}
proc N_VSpace*(v: N_Vector, lrw: ptr sunindextype, liw: ptr sunindextype) {.impsundials_nvectorC.}
proc N_VGetArrayPointer*(v: N_Vector): ptr realtype {.impsundials_nvectorC.}
proc N_VSetArrayPointer*(v_data: ptr realtype, v: N_Vector) {.impsundials_nvectorC.}
proc N_VGetCommunicator*(v: N_Vector): pointer {.impsundials_nvectorC.}
proc N_VGetLength*(v: N_Vector): sunindextype {.impsundials_nvectorC.}

#  standard vector operations
proc N_VLinearSum*(a: realtype, x: N_Vector, b: realtype, y: N_Vector, z: N_Vector) {.impsundials_nvectorC.}
proc N_VConst*(c: realtype, z: N_Vector) {.impsundials_nvectorC.}
proc N_VProd*(x: N_Vector, y: N_Vector, z: N_Vector) {.impsundials_nvectorC.}
proc N_VDiv*(x: N_Vector, y: N_Vector, z: N_Vector) {.impsundials_nvectorC.}
proc N_VScale*(c: realtype, x: N_Vector, z: N_Vector) {.impsundials_nvectorC.}
proc N_VAbs*(x: N_Vector, z: N_Vector) {.impsundials_nvectorC.}
proc N_VInv*(x: N_Vector, z: N_Vector) {.impsundials_nvectorC.}
proc N_VAddConst*(x: N_Vector, b: realtype, z: N_Vector) {.impsundials_nvectorC.}
proc N_VDotProd*(x: N_Vector, y: N_Vector): realtype {.impsundials_nvectorC.}
proc N_VMaxNorm*(x: N_Vector): realtype {.impsundials_nvectorC.}
proc N_VWrmsNorm*(x: N_Vector, w: N_Vector): realtype {.impsundials_nvectorC.}
proc N_VWrmsNormMask*(x: N_Vector, w: N_Vector, id: N_Vector): realtype {.impsundials_nvectorC.}
proc N_VMin*(x: N_Vector): realtype {.impsundials_nvectorC.}
proc N_VWL2Norm*(x: N_Vector, w: N_Vector): realtype {.impsundials_nvectorC.}
proc N_VL1Norm*(x: N_Vector): realtype {.impsundials_nvectorC.}
proc N_VCompare*(c: realtype, x: N_Vector, z: N_Vector) {.impsundials_nvectorC.}
proc N_VInvTest*(x: N_Vector, z: N_Vector): cint {.impsundials_nvectorC.}
proc N_VConstrMask*(c: N_Vector, x: N_Vector, m: N_Vector): cint {.impsundials_nvectorC.}
proc N_VMinQuotient*(num: N_Vector, denom: N_Vector): realtype {.impsundials_nvectorC.}

#  OPTIONAL fused vector operations
proc N_VLinearCombination*(nvec: cint, c: ptr realtype, X: ptr N_Vector, z: N_Vector): cint {.impsundials_nvectorC.}
proc N_VScaleAddMulti*(nvec: cint, a: ptr realtype, x: N_Vector, Y: ptr N_Vector, Z: ptr N_Vector): cint {.impsundials_nvectorC.}
proc N_VDotProdMulti*(nvec: cint, x: N_Vector, Y: ptr N_Vector, dotprods: ptr realtype): cint {.impsundials_nvectorC.}

#  OPTIONAL vector array operations
proc N_VLinearSumVectorArray*(nvec: cint, a: realtype, X: ptr N_Vector, b: realtype, Y: ptr N_Vector, Z: ptr N_Vector): cint {.impsundials_nvectorC.}
proc N_VScaleVectorArray*(nvec: cint, c: ptr realtype, X: ptr N_Vector, Z: ptr N_Vector): cint {.impsundials_nvectorC.}
proc N_VConstVectorArray*(nvec: cint, c: realtype, Z: ptr N_Vector): cint {.impsundials_nvectorC.}
proc N_VWrmsNormVectorArray*(nvec: cint, X: ptr N_Vector, W: ptr N_Vector, nrm: ptr realtype): cint {.impsundials_nvectorC.}
proc N_VWrmsNormMaskVectorArray*(nvec: cint, X: ptr N_Vector, W: ptr N_Vector, id: N_Vector, nrm: ptr realtype): cint {.impsundials_nvectorC.}
proc N_VScaleAddMultiVectorArray*(nvec: cint, nsum: cint, a: ptr realtype, X: ptr N_Vector, Y: ptr ptr N_Vector, Z: ptr ptr N_Vector): cint {.impsundials_nvectorC.}
proc N_VLinearCombinationVectorArray*(nvec: cint, nsum: cint, c: ptr realtype, X: ptr ptr N_Vector, Z: ptr N_Vector): cint {.impsundials_nvectorC.}

#  OPTIONAL local reduction kernels (no parallel communication)
proc N_VDotProdLocal*(x: N_Vector, y: N_Vector): realtype {.impsundials_nvectorC.}
proc N_VMaxNormLocal*(x: N_Vector): realtype {.impsundials_nvectorC.}
proc N_VMinLocal*(x: N_Vector): realtype {.impsundials_nvectorC.}
proc N_VL1NormLocal*(x: N_Vector): realtype {.impsundials_nvectorC.}
proc N_VWSqrSumLocal*(x: N_Vector, w: N_Vector): realtype {.impsundials_nvectorC.}
proc N_VWSqrSumMaskLocal*(x: N_Vector, w: N_Vector, id: N_Vector): realtype {.impsundials_nvectorC.}
proc N_VInvTestLocal*(x: N_Vector, z: N_Vector): cint {.impsundials_nvectorC.}
proc N_VConstrMaskLocal*(c: N_Vector, x: N_Vector, m: N_Vector): cint {.impsundials_nvectorC.}
proc N_VMinQuotientLocal*(num: N_Vector, denom: N_Vector): realtype {.impsundials_nvectorC.}

#  -----------------------------------------------------------------
#  * Additional functions exported by NVECTOR module
#  * -----------------------------------------------------------------
proc N_VCloneEmptyVectorArray*(count: cint, w: N_Vector): ptr N_Vector {.impsundials_nvectorC.}
proc N_VCloneVectorArray*(count: cint, w: N_Vector): ptr N_Vector {.impsundials_nvectorC.}
proc N_VDestroyVectorArray*(vs: ptr N_Vector, count: cint) {.impsundials_nvectorC.}

# Importing /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/nvector/nvector_serial.h
# Generated at 2019-07-29T21:21:32+02:00
# Command line:
#   /home/jose/.nimble/pkgs/nimterop-#head/nimterop/toast --preprocess --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/lib64 --pnim --dynlib=libsundials_nvecserial --nim:/home/jose/.choosenim/toolchains/nim-0.20.2/bin/nim --pluginSourcePath=/tmp/nimterop_170946992310022160.nim /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/nvector/nvector_serial.h

{.hint[ConvFromXtoItselfNotNeeded]: off.}

import nimterop/types

{.pragma: impnvector_serial, importc.}
{.pragma: impnvector_serialC, impnvector_serial, cdecl, dynlib: libsundials_nvecserial.}

type

#  -----------------------------------------------------------------
#  * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh, Radu Serban,
#  *                and Aaron Collier @ LLNL
#  * -----------------------------------------------------------------
#  * SUNDIALS Copyright Start
#  * Copyright (c) 2002-2019, Lawrence Livermore National Security
#  * and Southern Methodist University.
#  * All rights reserved.
#  *
#  * See the top-level LICENSE and NOTICE files for details.
#  *
#  * SPDX-License-Identifier: BSD-3-Clause
#  * SUNDIALS Copyright End
#  * -----------------------------------------------------------------
#  * This is the header file for the serial implementation of the
#  * NVECTOR module.
#  *
#  * Notes:
#  *
#  *   - The definition of the generic N_Vector structure can be found
#  *     in the header file sundials_nvector.h.
#  *
#  *   - The definition of the type 'realtype' can be found in the
#  *     header file sundials_types.h, and it may be changed (at the
#  *     configuration stage) according to the user's needs.
#  *     The sundials_types.h file also contains the definition
#  *     for the type 'booleantype'.
#  *
#  *   - N_Vector arguments to arithmetic vector operations need not
#  *     be distinct. For example, the following call:
#  *
#  *       N_VLinearSum_Serial(a,x,b,y,y);
#  *
#  *     (which stores the result of the operation a*x+b*y in y)
#  *     is legal.
#  * -----------------------------------------------------------------
#
#  * -----------------------------------------------------------------
#  * SERIAL implementation of N_Vector
#  * -----------------------------------------------------------------
#
  N_VectorContent_Serial_Base* {.importc: "struct _N_VectorContent_Serial", bycopy.} = object
    length*: sunindextype
    own_data*: cint
    data*: ptr realtype
  N_VectorContent_Serial* {.impnvector_serial.} = ptr N_VectorContent_Serial_Base

#
#  * -----------------------------------------------------------------
#  * Macros NV_CONTENT_S, NV_DATA_S, NV_OWN_DATA_S,
#  *        NV_LENGTH_S, and NV_Ith_S
#  * -----------------------------------------------------------------
#
#
#  * -----------------------------------------------------------------
#  * Functions exported by nvector_serial
#  * -----------------------------------------------------------------
#
proc N_VNew_Serial*(vec_length: sunindextype): N_Vector {.impnvector_serialC.}
proc N_VNewEmpty_Serial*(vec_length: sunindextype): N_Vector {.impnvector_serialC.}
proc N_VMake_Serial*(vec_length: sunindextype, v_data: ptr realtype): N_Vector {.impnvector_serialC.}
proc N_VCloneVectorArray_Serial*(count: cint, w: N_Vector): ptr N_Vector {.impnvector_serialC.}
proc N_VCloneVectorArrayEmpty_Serial*(count: cint, w: N_Vector): ptr N_Vector {.impnvector_serialC.}
proc N_VDestroyVectorArray_Serial*(vs: ptr N_Vector, count: cint) {.impnvector_serialC.}
proc N_VGetLength_Serial*(v: N_Vector): sunindextype {.impnvector_serialC.}
proc N_VPrint_Serial*(v: N_Vector) {.impnvector_serialC.}
proc N_VPrintFile_Serial*(v: N_Vector, outfile: ptr FILE) {.impnvector_serialC.}
proc N_VGetVectorID_Serial*(v: N_Vector): N_Vector_ID {.impnvector_serialC.}
proc N_VCloneEmpty_Serial*(w: N_Vector): N_Vector {.impnvector_serialC.}
proc N_VClone_Serial*(w: N_Vector): N_Vector {.impnvector_serialC.}
proc N_VDestroy_Serial*(v: N_Vector) {.impnvector_serialC.}
proc N_VSpace_Serial*(v: N_Vector, lrw: ptr sunindextype, liw: ptr sunindextype) {.impnvector_serialC.}
proc N_VGetArrayPointer_Serial*(v: N_Vector): ptr realtype {.impnvector_serialC.}
proc N_VSetArrayPointer_Serial*(v_data: ptr realtype, v: N_Vector) {.impnvector_serialC.}

#  standard vector operations
proc N_VLinearSum_Serial*(a: realtype, x: N_Vector, b: realtype, y: N_Vector, z: N_Vector) {.impnvector_serialC.}
proc N_VConst_Serial*(c: realtype, z: N_Vector) {.impnvector_serialC.}
proc N_VProd_Serial*(x: N_Vector, y: N_Vector, z: N_Vector) {.impnvector_serialC.}
proc N_VDiv_Serial*(x: N_Vector, y: N_Vector, z: N_Vector) {.impnvector_serialC.}
proc N_VScale_Serial*(c: realtype, x: N_Vector, z: N_Vector) {.impnvector_serialC.}
proc N_VAbs_Serial*(x: N_Vector, z: N_Vector) {.impnvector_serialC.}
proc N_VInv_Serial*(x: N_Vector, z: N_Vector) {.impnvector_serialC.}
proc N_VAddConst_Serial*(x: N_Vector, b: realtype, z: N_Vector) {.impnvector_serialC.}
proc N_VDotProd_Serial*(x: N_Vector, y: N_Vector): realtype {.impnvector_serialC.}
proc N_VMaxNorm_Serial*(x: N_Vector): realtype {.impnvector_serialC.}
proc N_VWrmsNorm_Serial*(x: N_Vector, w: N_Vector): realtype {.impnvector_serialC.}
proc N_VWrmsNormMask_Serial*(x: N_Vector, w: N_Vector, id: N_Vector): realtype {.impnvector_serialC.}
proc N_VMin_Serial*(x: N_Vector): realtype {.impnvector_serialC.}
proc N_VWL2Norm_Serial*(x: N_Vector, w: N_Vector): realtype {.impnvector_serialC.}
proc N_VL1Norm_Serial*(x: N_Vector): realtype {.impnvector_serialC.}
proc N_VCompare_Serial*(c: realtype, x: N_Vector, z: N_Vector) {.impnvector_serialC.}
proc N_VInvTest_Serial*(x: N_Vector, z: N_Vector): cint {.impnvector_serialC.}
proc N_VConstrMask_Serial*(c: N_Vector, x: N_Vector, m: N_Vector): cint {.impnvector_serialC.}
proc N_VMinQuotient_Serial*(num: N_Vector, denom: N_Vector): realtype {.impnvector_serialC.}

#  fused vector operations
proc N_VLinearCombination_Serial*(nvec: cint, c: ptr realtype, V: ptr N_Vector, z: N_Vector): cint {.impnvector_serialC.}
proc N_VScaleAddMulti_Serial*(nvec: cint, a: ptr realtype, x: N_Vector, Y: ptr N_Vector, Z: ptr N_Vector): cint {.impnvector_serialC.}
proc N_VDotProdMulti_Serial*(nvec: cint, x: N_Vector, Y: ptr N_Vector, dotprods: ptr realtype): cint {.impnvector_serialC.}

#  vector array operations
proc N_VLinearSumVectorArray_Serial*(nvec: cint, a: realtype, X: ptr N_Vector, b: realtype, Y: ptr N_Vector, Z: ptr N_Vector): cint {.impnvector_serialC.}
proc N_VScaleVectorArray_Serial*(nvec: cint, c: ptr realtype, X: ptr N_Vector, Z: ptr N_Vector): cint {.impnvector_serialC.}
proc N_VConstVectorArray_Serial*(nvecs: cint, c: realtype, Z: ptr N_Vector): cint {.impnvector_serialC.}
proc N_VWrmsNormVectorArray_Serial*(nvecs: cint, X: ptr N_Vector, W: ptr N_Vector, nrm: ptr realtype): cint {.impnvector_serialC.}
proc N_VWrmsNormMaskVectorArray_Serial*(nvecs: cint, X: ptr N_Vector, W: ptr N_Vector, id: N_Vector, nrm: ptr realtype): cint {.impnvector_serialC.}
proc N_VScaleAddMultiVectorArray_Serial*(nvec: cint, nsum: cint, a: ptr realtype, X: ptr N_Vector, Y: ptr ptr N_Vector, Z: ptr ptr N_Vector): cint {.impnvector_serialC.}
proc N_VLinearCombinationVectorArray_Serial*(nvec: cint, nsum: cint, c: ptr realtype, X: ptr ptr N_Vector, Z: ptr N_Vector): cint {.impnvector_serialC.}

#  OPTIONAL local reduction kernels (no parallel communication)
proc N_VWSqrSumLocal_Serial*(x: N_Vector, w: N_Vector): realtype {.impnvector_serialC.}
proc N_VWSqrSumMaskLocal_Serial*(x: N_Vector, w: N_Vector, id: N_Vector): realtype {.impnvector_serialC.}

#
#  * -----------------------------------------------------------------
#  * Enable / disable fused vector operations
#  * -----------------------------------------------------------------
#
proc N_VEnableFusedOps_Serial*(v: N_Vector, tf: cint): cint {.impnvector_serialC.}
proc N_VEnableLinearCombination_Serial*(v: N_Vector, tf: cint): cint {.impnvector_serialC.}
proc N_VEnableScaleAddMulti_Serial*(v: N_Vector, tf: cint): cint {.impnvector_serialC.}
proc N_VEnableDotProdMulti_Serial*(v: N_Vector, tf: cint): cint {.impnvector_serialC.}
proc N_VEnableLinearSumVectorArray_Serial*(v: N_Vector, tf: cint): cint {.impnvector_serialC.}
proc N_VEnableScaleVectorArray_Serial*(v: N_Vector, tf: cint): cint {.impnvector_serialC.}
proc N_VEnableConstVectorArray_Serial*(v: N_Vector, tf: cint): cint {.impnvector_serialC.}
proc N_VEnableWrmsNormVectorArray_Serial*(v: N_Vector, tf: cint): cint {.impnvector_serialC.}
proc N_VEnableWrmsNormMaskVectorArray_Serial*(v: N_Vector, tf: cint): cint {.impnvector_serialC.}
proc N_VEnableScaleAddMultiVectorArray_Serial*(v: N_Vector, tf: cint): cint {.impnvector_serialC.}
proc N_VEnableLinearCombinationVectorArray_Serial*(v: N_Vector, tf: cint): cint {.impnvector_serialC.}

# Importing /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_nonlinearsolver.h
# Generated at 2019-07-29T21:21:33+02:00
# Command line:
#   /home/jose/.nimble/pkgs/nimterop-#head/nimterop/toast --preprocess --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/lib64 --pnim --nim:/home/jose/.choosenim/toolchains/nim-0.20.2/bin/nim --pluginSourcePath=/tmp/nimterop_170946992310022160.nim /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_nonlinearsolver.h

{.hint[ConvFromXtoItselfNotNeeded]: off.}

import nimterop/types

#  -----------------------------------------------------------------------------
#  * SUNNonlinearSolver types
#  * ---------------------------------------------------------------------------
defineEnum(SUNNonlinearSolver_Type)

const
  headersundials_nonlinearsolver {.used.} = "/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_nonlinearsolver.h"
  SUNNONLINEARSOLVER_ROOTFIND* = 0.SUNNonlinearSolver_Type
  SUNNONLINEARSOLVER_FIXEDPOINT* = 1.SUNNonlinearSolver_Type

#  -----------------------------------------------------------------------------
#  * SUNNonlinearSolver return values
#  * ---------------------------------------------------------------------------
  SUN_NLS_SUCCESS* = 0

#  Recoverable
#  Unrecoverable
  SUN_NLS_MEM_NULL* = -1
  SUN_NLS_MEM_FAIL* = -2
  SUN_NLS_ILL_INPUT* = -3
  SUN_NLS_VECTOROP_ERR* = -4

{.pragma: impsundials_nonlinearsolver, importc, header: headersundials_nonlinearsolver.}
{.pragma: impsundials_nonlinearsolverC, impsundials_nonlinearsolver, cdecl.}

type

#  -----------------------------------------------------------------------------
#  * Programmer(s): David J. Gardner @ LLNL
#  * -----------------------------------------------------------------------------
#  * SUNDIALS Copyright Start
#  * Copyright (c) 2002-2019, Lawrence Livermore National Security
#  * and Southern Methodist University.
#  * All rights reserved.
#  *
#  * See the top-level LICENSE and NOTICE files for details.
#  *
#  * SPDX-License-Identifier: BSD-3-Clause
#  * SUNDIALS Copyright End
#  * -----------------------------------------------------------------------------
#  * This is the header file for a generic nonlinear solver package. It defines
#  * the SUNNonlinearSolver structure (_generic_SUNNonlinearSolver) which contains
#  * the following fields:
#  *   - an implementation-dependent 'content' field which contains any internal
#  *     data required by the solver
#  *   - an 'ops' filed which contains a structure listing operations acting on/by
#  *     such solvers
#  *
#  * We consider iterative nonlinear solvers for systems in both root finding
#  * (F(y) = 0) or fixed-point (G(y) = y) form. As a result, some of the routines
#  * are applicable only to one type of nonlinear solver.
#  * -----------------------------------------------------------------------------
#  * This header file contains:
#  *   - function types supplied to a SUNNonlinearSolver,
#  *   - enumeration constants for SUNDIALS-defined nonlinear solver types,
#  *   - type declarations for the _generic_SUNNonlinearSolver and
#  *     _generic_SUNNonlinearSolver_Ops structures, as well as references to
#  *     pointers to such structures (SUNNonlinearSolver),
#  *   - prototypes for the nonlinear solver functions which operate
#  *     on/by SUNNonlinearSolver objects, and
#  *   - return codes for SUNLinearSolver objects.
#  * -----------------------------------------------------------------------------
#  * At a minimum, a particular implementation of a SUNNonlinearSolver must do the
#  * following:
#  *   - specify the 'content' field of a SUNNonlinearSolver,
#  *   - implement the operations on/by the SUNNonlinearSovler objects,
#  *   - provide a constructor routine for new SUNNonlinearSolver objects
#  *
#  * Additionally, a SUNNonlinearSolver implementation may provide the following:
#  *   - "Set" routines to control solver-specific parameters/options
#  *   - "Get" routines to access solver-specific performance metrics
#  * ---------------------------------------------------------------------------
#  -----------------------------------------------------------------------------
#  *  Forward references for SUNNonlinearSolver types defined below
#  * ---------------------------------------------------------------------------
#  Forward reference for pointer to SUNNonlinearSolver_Ops object
  SUNNonlinearSolver_Ops* {.impsundials_nonlinearsolver.} = ptr generic_SUNNonlinearSolver_Ops

#  Forward reference for pointer to SUNNonlinearSolver object
  SUNNonlinearSolver* {.impsundials_nonlinearsolver.} = ptr generic_SUNNonlinearSolver

#  -----------------------------------------------------------------------------
#  * Integrator supplied function types
#  * ---------------------------------------------------------------------------
  SUNNonlinSolSysFn* {.impsundials_nonlinearsolver.} = proc(y: N_Vector, F: N_Vector, mem: pointer): cint {.cdecl.}
  SUNNonlinSolLSetupFn* {.impsundials_nonlinearsolver.} = proc(y: N_Vector, F: N_Vector, jbad: cint, jcur: ptr cint, mem: pointer): cint {.cdecl.}
  SUNNonlinSolLSolveFn* {.impsundials_nonlinearsolver.} = proc(y: N_Vector, b: N_Vector, mem: pointer): cint {.cdecl.}
  SUNNonlinSolConvTestFn* {.impsundials_nonlinearsolver.} = proc(NLS: SUNNonlinearSolver, y: N_Vector, del: N_Vector, tol: realtype, ewt: N_Vector, mem: pointer): cint {.cdecl.}

#  -----------------------------------------------------------------------------
#  * Generic definition of SUNNonlinearSolver
#  * ---------------------------------------------------------------------------
#  Structure containing function pointers to nonlinear solver operations
  generic_SUNNonlinearSolver_Ops* {.importc: "struct _generic_SUNNonlinearSolver_Ops", header: headersundials_nonlinearsolver, bycopy.} = object
    gettype*: proc(a1: SUNNonlinearSolver): SUNNonlinearSolver_Type {.cdecl.}
    initialize*: proc(a1: SUNNonlinearSolver): cint {.cdecl.}
    setup*: proc(a1: SUNNonlinearSolver, a2: N_Vector, a3: pointer): cint {.cdecl.}
    solve*: proc(a1: SUNNonlinearSolver, a2: N_Vector, a3: N_Vector, a4: N_Vector, a5: realtype, a6: cint, a7: pointer): cint {.cdecl.}
    free*: proc(a1: SUNNonlinearSolver): cint {.cdecl.}
    setsysfn*: proc(a1: SUNNonlinearSolver, a2: SUNNonlinSolSysFn): cint {.cdecl.}
    setlsetupfn*: proc(a1: SUNNonlinearSolver, a2: SUNNonlinSolLSetupFn): cint {.cdecl.}
    setlsolvefn*: proc(a1: SUNNonlinearSolver, a2: SUNNonlinSolLSolveFn): cint {.cdecl.}
    setctestfn*: proc(a1: SUNNonlinearSolver, a2: SUNNonlinSolConvTestFn): cint {.cdecl.}
    setmaxiters*: proc(a1: SUNNonlinearSolver, a2: cint): cint {.cdecl.}
    getnumiters*: proc(a1: SUNNonlinearSolver, a2: ptr clong): cint {.cdecl.}
    getcuriter*: proc(a1: SUNNonlinearSolver, a2: ptr cint): cint {.cdecl.}
    getnumconvfails*: proc(a1: SUNNonlinearSolver, a2: ptr clong): cint {.cdecl.}

#  A nonlinear solver is a structure with an implementation-dependent 'content'
#    field, and a pointer to a structure of solver nonlinear solver operations
#    corresponding to that implementation.
  generic_SUNNonlinearSolver* {.importc: "struct _generic_SUNNonlinearSolver", header: headersundials_nonlinearsolver, bycopy.} = object
    content*: pointer
    ops*: SUNNonlinearSolver_Ops

#  -----------------------------------------------------------------------------
#  * Functions exported by SUNNonlinearSolver module
#  * ---------------------------------------------------------------------------
#  empty constructor/destructor
proc SUNNonlinSolNewEmpty*(): SUNNonlinearSolver {.impsundials_nonlinearsolverC.}
proc SUNNonlinSolFreeEmpty*(NLS: SUNNonlinearSolver) {.impsundials_nonlinearsolverC.}

#  core functions
proc SUNNonlinSolGetType*(NLS: SUNNonlinearSolver): SUNNonlinearSolver_Type {.impsundials_nonlinearsolverC.}
proc SUNNonlinSolInitialize*(NLS: SUNNonlinearSolver): cint {.impsundials_nonlinearsolverC.}
proc SUNNonlinSolSetup*(NLS: SUNNonlinearSolver, y: N_Vector, mem: pointer): cint {.impsundials_nonlinearsolverC.}
proc SUNNonlinSolSolve*(NLS: SUNNonlinearSolver, y0: N_Vector, y: N_Vector, w: N_Vector, tol: realtype, callLSetup: cint, mem: pointer): cint {.impsundials_nonlinearsolverC.}
proc SUNNonlinSolFree*(NLS: SUNNonlinearSolver): cint {.impsundials_nonlinearsolverC.}

#  set functions
proc SUNNonlinSolSetSysFn*(NLS: SUNNonlinearSolver, SysFn: SUNNonlinSolSysFn): cint {.impsundials_nonlinearsolverC.}
proc SUNNonlinSolSetLSetupFn*(NLS: SUNNonlinearSolver, SetupFn: SUNNonlinSolLSetupFn): cint {.impsundials_nonlinearsolverC.}
proc SUNNonlinSolSetLSolveFn*(NLS: SUNNonlinearSolver, SolveFn: SUNNonlinSolLSolveFn): cint {.impsundials_nonlinearsolverC.}
proc SUNNonlinSolSetConvTestFn*(NLS: SUNNonlinearSolver, CTestFn: SUNNonlinSolConvTestFn): cint {.impsundials_nonlinearsolverC.}
proc SUNNonlinSolSetMaxIters*(NLS: SUNNonlinearSolver, maxiters: cint): cint {.impsundials_nonlinearsolverC.}

#  get functions
proc SUNNonlinSolGetNumIters*(NLS: SUNNonlinearSolver, niters: ptr clong): cint {.impsundials_nonlinearsolverC.}
proc SUNNonlinSolGetCurIter*(NLS: SUNNonlinearSolver, iter: ptr cint): cint {.impsundials_nonlinearsolverC.}
proc SUNNonlinSolGetNumConvFails*(NLS: SUNNonlinearSolver, nconvfails: ptr clong): cint {.impsundials_nonlinearsolverC.}

# Importing /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_direct.h
# Generated at 2019-07-29T21:21:33+02:00
# Command line:
#   /home/jose/.nimble/pkgs/nimterop-#head/nimterop/toast --preprocess --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/lib64 --pnim --nim:/home/jose/.choosenim/toolchains/nim-0.20.2/bin/nim --pluginSourcePath=/tmp/nimterop_170946992310022160.nim /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_direct.h

{.hint[ConvFromXtoItselfNotNeeded]: off.}

import nimterop/types

const
  headersundials_direct {.used.} = "/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_direct.h"

#  -----------------------------------------------------------------
#  * Programmer: Radu Serban @ LLNL
#  * -----------------------------------------------------------------
#  * SUNDIALS Copyright Start
#  * Copyright (c) 2002-2019, Lawrence Livermore National Security
#  * and Southern Methodist University.
#  * All rights reserved.
#  *
#  * See the top-level LICENSE and NOTICE files for details.
#  *
#  * SPDX-License-Identifier: BSD-3-Clause
#  * SUNDIALS Copyright End
#  * -----------------------------------------------------------------
#  * This header file contains definitions and declarations for use by
#  * generic direct linear solvers for Ax = b. It defines types for
#  * dense and banded matrices and corresponding accessor macros.
#  * -----------------------------------------------------------------
#
#  * =================================================================
#  *                C O N S T A N T S
#  * =================================================================
#
#
#  *  SUNDIALS_DENSE: dense matrix
#  *  SUNDIALS_BAND:  banded matrix
#
  SUNDIALS_DENSE* = 1
  SUNDIALS_BAND* = 2

{.pragma: impsundials_direct, importc, header: headersundials_direct.}
{.pragma: impsundials_directC, impsundials_direct, cdecl.}

type

#
#  * ==================================================================
#  * Type definitions
#  * ==================================================================
#
#
#  * -----------------------------------------------------------------
#  * Type : DlsMat
#  * -----------------------------------------------------------------
#  * The type DlsMat is defined to be a pointer to a structure
#  * with various sizes, a data field, and an array of pointers to
#  * the columns which defines a dense or band matrix for use in
#  * direct linear solvers. The M and N fields indicates the number
#  * of rows and columns, respectively. The data field is a one
#  * dimensional array used for component storage. The cols field
#  * stores the pointers in data for the beginning of each column.
#  * -----------------------------------------------------------------
#  * For DENSE matrices, the relevant fields in DlsMat are:
#  *    type  = SUNDIALS_DENSE
#  *    M     - number of rows
#  *    N     - number of columns
#  *    ldim  - leading dimension (ldim >= M)
#  *    data  - pointer to a contiguous block of realtype variables
#  *    ldata - length of the data array =ldim*N
#  *    cols  - array of pointers. cols[j] points to the first element
#  *            of the j-th column of the matrix in the array data.
#  *
#  * The elements of a dense matrix are stored columnwise (i.e. columns
#  * are stored one on top of the other in memory).
#  * If A is of type DlsMat, then the (i,j)th element of A (with
#  * 0 <= i < M and 0 <= j < N) is given by (A->data)[j*n+i].
#  *
#  * The DENSE_COL and DENSE_ELEM macros below allow a user to access
#  * efficiently individual matrix elements without writing out explicit
#  * data structure references and without knowing too much about the
#  * underlying element storage. The only storage assumption needed is
#  * that elements are stored columnwise and that a pointer to the
#  * jth column of elements can be obtained via the DENSE_COL macro.
#  * -----------------------------------------------------------------
#  * For BAND matrices, the relevant fields in DlsMat are:
#  *    type  = SUNDIALS_BAND
#  *    M     - number of rows
#  *    N     - number of columns
#  *    mu    - upper bandwidth, 0 <= mu <= min(M,N)
#  *    ml    - lower bandwidth, 0 <= ml <= min(M,N)
#  *    s_mu  - storage upper bandwidth, mu <= s_mu <= N-1.
#  *            The dgbtrf routine writes the LU factors into the storage
#  *            for A. The upper triangular factor U, however, may have
#  *            an upper bandwidth as big as MIN(N-1,mu+ml) because of
#  *            partial pivoting. The s_mu field holds the upper
#  *            bandwidth allocated for A.
#  *    ldim  - leading dimension (ldim >= s_mu)
#  *    data  - pointer to a contiguous block of realtype variables
#  *    ldata - length of the data array =ldim*(s_mu+ml+1)
#  *    cols  - array of pointers. cols[j] points to the first element
#  *            of the j-th column of the matrix in the array data.
#  *
#  * The BAND_COL, BAND_COL_ELEM, and BAND_ELEM macros below allow a
#  * user to access individual matrix elements without writing out
#  * explicit data structure references and without knowing too much
#  * about the underlying element storage. The only storage assumption
#  * needed is that elements are stored columnwise and that a pointer
#  * into the jth column of elements can be obtained via the BAND_COL
#  * macro. The BAND_COL_ELEM macro selects an element from a column
#  * which has already been isolated via BAND_COL. The macro
#  * BAND_COL_ELEM allows the user to avoid the translation
#  * from the matrix location (i,j) to the index in the array returned
#  * by BAND_COL at which the (i,j)th element is stored.
#  * -----------------------------------------------------------------
#
  DlsMat* {.importc: "struct _DlsMat", header: headersundials_direct, bycopy.} = object
    `type`*: cint
    M*: sunindextype
    N*: sunindextype
    ldim*: sunindextype
    mu*: sunindextype
    ml*: sunindextype
    s_mu*: sunindextype
    data*: ptr realtype
    ldata*: sunindextype
    cols*: ptr ptr realtype

#
#  * ==================================================================
#  * Data accessor macros
#  * ==================================================================
#
#
#  * -----------------------------------------------------------------
#  * DENSE_COL and DENSE_ELEM
#  * -----------------------------------------------------------------
#  *
#  * DENSE_COL(A,j) references the jth column of the M-by-N dense
#  * matrix A, 0 <= j < N. The type of the expression DENSE_COL(A,j)
#  * is (realtype *). After the assignment col_j = DENSE_COL(A,j),
#  * col_j may be treated as an array indexed from 0 to M-1.
#  * The (i,j)-th element of A is thus referenced by col_j[i].
#  *
#  * DENSE_ELEM(A,i,j) references the (i,j)th element of the dense
#  * M-by-N matrix A, 0 <= i < M ; 0 <= j < N.
#  *
#  * -----------------------------------------------------------------
#
#
#  * -----------------------------------------------------------------
#  * BAND_COL, BAND_COL_ELEM, and BAND_ELEM
#  * -----------------------------------------------------------------
#  *
#  * BAND_COL(A,j) references the diagonal element of the jth column
#  * of the N by N band matrix A, 0 <= j <= N-1. The type of the
#  * expression BAND_COL(A,j) is realtype *. The pointer returned by
#  * the call BAND_COL(A,j) can be treated as an array which is
#  * indexed from -(A->mu) to (A->ml).
#  *
#  * BAND_COL_ELEM references the (i,j)th entry of the band matrix A
#  * when used in conjunction with BAND_COL. The index (i,j) should
#  * satisfy j-(A->mu) <= i <= j+(A->ml).
#  *
#  * BAND_ELEM(A,i,j) references the (i,j)th element of the M-by-N
#  * band matrix A, where 0 <= i,j <= N-1. The location (i,j) should
#  * further satisfy j-(A->mu) <= i <= j+(A->ml).
#  *
#  * -----------------------------------------------------------------
#
#
#  * ==================================================================
#  * Exported function prototypes (functions working on dlsMat)
#  * ==================================================================
#
#
#  * -----------------------------------------------------------------
#  * Function: NewDenseMat
#  * -----------------------------------------------------------------
#  * NewDenseMat allocates memory for an M-by-N dense matrix and
#  * returns the storage allocated (type DlsMat). NewDenseMat
#  * returns NULL if the request for matrix storage cannot be
#  * satisfied. See the above documentation for the type DlsMat
#  * for matrix storage details.
#  * -----------------------------------------------------------------
#
proc NewDenseMat*(M: sunindextype, N: sunindextype): DlsMat {.impsundials_directC.}

#
#  * -----------------------------------------------------------------
#  * Function: NewBandMat
#  * -----------------------------------------------------------------
#  * NewBandMat allocates memory for an M-by-N band matrix
#  * with upper bandwidth mu, lower bandwidth ml, and storage upper
#  * bandwidth smu. Pass smu as follows depending on whether A will
#  * be LU factored:
#  *
#  * (1) Pass smu = mu if A will not be factored.
#  *
#  * (2) Pass smu = MIN(N-1,mu+ml) if A will be factored.
#  *
#  * NewBandMat returns the storage allocated (type DlsMat) or
#  * NULL if the request for matrix storage cannot be satisfied.
#  * See the documentation for the type DlsMat for matrix storage
#  * details.
#  * -----------------------------------------------------------------
#
proc NewBandMat*(N: sunindextype, mu: sunindextype, ml: sunindextype, smu: sunindextype): DlsMat {.impsundials_directC.}

#
#  * -----------------------------------------------------------------
#  * Functions: DestroyMat
#  * -----------------------------------------------------------------
#  * DestroyMat frees the memory allocated by NewDenseMat or NewBandMat
#  * -----------------------------------------------------------------
#
proc DestroyMat*(A: DlsMat) {.impsundials_directC.}

#
#  * -----------------------------------------------------------------
#  * Function: NewIntArray
#  * -----------------------------------------------------------------
#  * NewIntArray allocates memory an array of N int's and returns
#  * the pointer to the memory it allocates. If the request for
#  * memory storage cannot be satisfied, it returns NULL.
#  * -----------------------------------------------------------------
#
proc NewIntArray*(N: cint): ptr cint {.impsundials_directC.}

#
#  * -----------------------------------------------------------------
#  * Function: NewIndexArray
#  * -----------------------------------------------------------------
#  * NewIndexArray allocates memory an array of N sunindextype's and
#  * returns the pointer to the memory it allocates. If the request
#  * for memory storage cannot be satisfied, it returns NULL.
#  * -----------------------------------------------------------------
#
proc NewIndexArray*(N: sunindextype): ptr sunindextype {.impsundials_directC.}

#
#  * -----------------------------------------------------------------
#  * Function: NewRealArray
#  * -----------------------------------------------------------------
#  * NewRealArray allocates memory an array of N realtype and returns
#  * the pointer to the memory it allocates. If the request for
#  * memory storage cannot be satisfied, it returns NULL.
#  * -----------------------------------------------------------------
#
proc NewRealArray*(N: sunindextype): ptr realtype {.impsundials_directC.}

#
#  * -----------------------------------------------------------------
#  * Function: DestroyArray
#  * -----------------------------------------------------------------
#  * DestroyArray frees memory allocated by NewIntArray, NewIndexArray,
#  * or NewRealArray.
#  * -----------------------------------------------------------------
#
proc DestroyArray*(p: pointer) {.impsundials_directC.}

#
#  * -----------------------------------------------------------------
#  * Function : AddIdentity
#  * -----------------------------------------------------------------
#  * AddIdentity adds 1.0 to the main diagonal (A_ii, i=0,1,...,N-1) of
#  * the M-by-N matrix A (M>= N) and stores the result back in A.
#  * AddIdentity is typically used with square matrices.
#  * AddIdentity does not check for M >= N and therefore a segmentation
#  * fault will occur if M < N!
#  * -----------------------------------------------------------------
#
proc AddIdentity*(A: DlsMat) {.impsundials_directC.}

#
#  * -----------------------------------------------------------------
#  * Function : SetToZero
#  * -----------------------------------------------------------------
#  * SetToZero sets all the elements of the M-by-N matrix A to 0.0.
#  * -----------------------------------------------------------------
#
proc SetToZero*(A: DlsMat) {.impsundials_directC.}

#
#  * -----------------------------------------------------------------
#  * Functions: PrintMat
#  * -----------------------------------------------------------------
#  * This function prints the M-by-N (dense or band) matrix A to
#  * outfile as it would normally appear on paper.
#  * It is intended as debugging tools with small values of M and N.
#  * The elements are printed using the %g/%lg/%Lg option.
#  * A blank line is printed before and after the matrix.
#  * -----------------------------------------------------------------
#
proc PrintMat*(A: DlsMat, outfile: ptr FILE) {.impsundials_directC.}

#
#  * ==================================================================
#  * Exported function prototypes (functions working on realtype**)
#  * ==================================================================
#
proc newDenseMat*(m: sunindextype, n: sunindextype): ptr ptr realtype {.impsundials_directC.}
proc newBandMat*(n: sunindextype, smu: sunindextype, ml: sunindextype): ptr ptr realtype {.impsundials_directC.}
proc destroyMat*(a: ptr ptr realtype) {.impsundials_directC.}
proc newIntArray*(n: cint): ptr cint {.impsundials_directC.}
proc newIndexArray*(n: sunindextype): ptr sunindextype {.impsundials_directC.}
proc newRealArray*(m: sunindextype): ptr realtype {.impsundials_directC.}
proc destroyArray*(v: pointer) {.impsundials_directC.}

# Importing /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_iterative.h
# Generated at 2019-07-29T21:21:33+02:00
# Command line:
#   /home/jose/.nimble/pkgs/nimterop-#head/nimterop/toast --preprocess --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/lib64 --pnim --nim:/home/jose/.choosenim/toolchains/nim-0.20.2/bin/nim --pluginSourcePath=/tmp/nimterop_170946992310022160.nim /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_iterative.h

{.hint[ConvFromXtoItselfNotNeeded]: off.}

import nimterop/types

#  -----------------------------------------------------------------
#  * Programmer(s): Scott D. Cohen and Alan C. Hindmarsh @ LLNL
#  * -----------------------------------------------------------------
#  * SUNDIALS Copyright Start
#  * Copyright (c) 2002-2019, Lawrence Livermore National Security
#  * and Southern Methodist University.
#  * All rights reserved.
#  *
#  * See the top-level LICENSE and NOTICE files for details.
#  *
#  * SPDX-License-Identifier: BSD-3-Clause
#  * SUNDIALS Copyright End
#  * -----------------------------------------------------------------
#  * This header file contains declarations intended for use by
#  * generic iterative solvers of Ax = b. The enumeration gives
#  * symbolic names for the type  of preconditioning to be used.
#  * The function type declarations give the prototypes for the
#  * functions to be called within an iterative linear solver, that
#  * are responsible for
#  *    multiplying A by a given vector v (ATimesFn),
#  *    setting up a preconditioner P (PSetupFn), and
#  *    solving the preconditioner equation Pz = r (PSolveFn).
#  * -----------------------------------------------------------------
#
#  * -----------------------------------------------------------------
#  * enum : types of preconditioning
#  * -----------------------------------------------------------------
#  * PREC_NONE  : The iterative linear solver should not use
#  *              preconditioning.
#  *
#  * PREC_LEFT  : The iterative linear solver uses preconditioning on
#  *              the left only.
#  *
#  * PREC_RIGHT : The iterative linear solver uses preconditioning on
#  *              the right only.
#  *
#  * PREC_BOTH  : The iterative linear solver uses preconditioning on
#  *              both the left and the right.
#  * -----------------------------------------------------------------
#
defineEnum(Enum_sundials_iterativeh1)

#
#  * -----------------------------------------------------------------
#  * enum : types of Gram-Schmidt routines
#  * -----------------------------------------------------------------
#  * MODIFIED_GS  : The iterative solver uses the modified
#  *                Gram-Schmidt routine ModifiedGS listed in this
#  *                file.
#  *
#  * CLASSICAL_GS : The iterative solver uses the classical
#  *                Gram-Schmidt routine ClassicalGS listed in this
#  *                file.
#  * -----------------------------------------------------------------
#
defineEnum(Enum_sundials_iterativeh2)

const
  headersundials_iterative {.used.} = "/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_iterative.h"
  PREC_NONE* = 0.Enum_sundials_iterativeh1
  PREC_LEFT* = 1.Enum_sundials_iterativeh1
  PREC_RIGHT* = 2.Enum_sundials_iterativeh1
  PREC_BOTH* = 3.Enum_sundials_iterativeh1
  MODIFIED_GS* = (1).Enum_sundials_iterativeh2
  CLASSICAL_GS* = (2).Enum_sundials_iterativeh2

{.pragma: impsundials_iterative, importc, header: headersundials_iterative.}
{.pragma: impsundials_iterativeC, impsundials_iterative, cdecl.}

type

#
#  * -----------------------------------------------------------------
#  * Type: ATimesFn
#  * -----------------------------------------------------------------
#  * An ATimesFn multiplies Av and stores the result in z. The
#  * caller is responsible for allocating memory for the z vector.
#  * The parameter A_data is a pointer to any information about A
#  * which the function needs in order to do its job. The vector v
#  * is unchanged. An ATimesFn returns 0 if successful and a
#  * non-zero value if unsuccessful.
#  * -----------------------------------------------------------------
#
  ATimesFn* {.impsundials_iterative.} = proc(A_data: pointer, v: N_Vector, z: N_Vector): cint {.cdecl.}

#
#  * -----------------------------------------------------------------
#  * Type: PSetupFn
#  * -----------------------------------------------------------------
#  * A PSetupFn is an integrator-supplied routine that accesses data
#  * stored in the integrator memory structure (P_data), and calls
#  * the user-supplied, integrator-specific preconditioner setup
#  * routine.
#  * -----------------------------------------------------------------
#
  PSetupFn* {.impsundials_iterative.} = proc(P_data: pointer): cint {.cdecl.}

#
#  * -----------------------------------------------------------------
#  * Type: PSolveFn
#  * -----------------------------------------------------------------
#  * A PSolveFn solves the preconditioner equation Pz = r for the
#  * vector z. The caller is responsible for allocating memory for
#  * the z vector. The parameter P_data is a pointer to any
#  * information about P which the function needs in order to do
#  * its job. The parameter lr is input, and indicates whether P
#  * is to be taken as the left preconditioner or the right
#  * preconditioner: lr = 1 for left and lr = 2 for right.
#  * If preconditioning is on one side only, lr can be ignored.
#  * If the preconditioner is iterative, then it should strive to
#  * solve the preconditioner equation so that
#  *     || Pz - r ||_wrms < tol
#  * where the weight vector for the WRMS norm may be accessed from
#  * the main integrator memory structure.
#  * The vector r should not be modified by the PSolveFn.
#  * A PSolveFn returns 0 if successful and a non-zero value if
#  * unsuccessful.  On a failure, a negative return value indicates
#  * an unrecoverable condition, while a positive value indicates
#  * a recoverable one, in which the calling routine may reattempt
#  * the solution after updating preconditioner data.
#  * -----------------------------------------------------------------
#
  PSolveFn* {.impsundials_iterative.} = proc(P_data: pointer, r: N_Vector, z: N_Vector, tol: realtype, lr: cint): cint {.cdecl.}

#
#  * -----------------------------------------------------------------
#  * Function: ModifiedGS
#  * -----------------------------------------------------------------
#  * ModifiedGS performs a modified Gram-Schmidt orthogonalization
#  * of the N_Vector v[k] against the p unit N_Vectors at
#  * v[k-1], v[k-2], ..., v[k-p].
#  *
#  * v is an array of (k+1) N_Vectors v[i], i=0, 1, ..., k.
#  * v[k-1], v[k-2], ..., v[k-p] are assumed to have L2-norm
#  * equal to 1.
#  *
#  * h is the output k by k Hessenberg matrix of inner products.
#  * This matrix must be allocated row-wise so that the (i,j)th
#  * entry is h[i][j]. The inner products (v[i],v[k]),
#  * i=i0, i0+1, ..., k-1, are stored at h[i][k-1]. Here
#  * i0=SUNMAX(0,k-p).
#  *
#  * k is the index of the vector in the v array that needs to be
#  * orthogonalized against previous vectors in the v array.
#  *
#  * p is the number of previous vectors in the v array against
#  * which v[k] is to be orthogonalized.
#  *
#  * new_vk_norm is a pointer to memory allocated by the caller to
#  * hold the Euclidean norm of the orthogonalized vector v[k].
#  *
#  * If (k-p) < 0, then ModifiedGS uses p=k. The orthogonalized
#  * v[k] is NOT normalized and is stored over the old v[k]. Once
#  * the orthogonalization has been performed, the Euclidean norm
#  * of v[k] is stored in (*new_vk_norm).
#  *
#  * ModifiedGS returns 0 to indicate success. It cannot fail.
#  * -----------------------------------------------------------------
#
proc cModifiedGS*(v: ptr N_Vector, h: ptr ptr realtype, k: cint, p: cint, new_vk_norm: ptr realtype): cint {.importc: "ModifiedGS", header: headersundials_iterative, cdecl.}

#
#  * -----------------------------------------------------------------
#  * Function: ClassicalGS
#  * -----------------------------------------------------------------
#  * ClassicalGS performs a classical Gram-Schmidt
#  * orthogonalization of the N_Vector v[k] against the p unit
#  * N_Vectors at v[k-1], v[k-2], ..., v[k-p]. The parameters v, h,
#  * k, p, and new_vk_norm are as described in the documentation
#  * for ModifiedGS.
#  *
#  * stemp is a length k+1 array of realtype which can be used as
#  * workspace by the ClassicalGS routine.
#  *
#  * vtemp is an N_Vector array of k+1 vectors which can be used as
#  * workspace by the ClassicalGS routine.
#  *
#  * ClassicalGS returns 0 to indicate success.
#  * -----------------------------------------------------------------
#
proc cClassicalGS*(v: ptr N_Vector, h: ptr ptr realtype, k: cint, p: cint, new_vk_norm: ptr realtype, stemp: ptr realtype, vtemp: ptr N_Vector): cint {.importc: "ClassicalGS", header: headersundials_iterative, cdecl.}

#
#  * -----------------------------------------------------------------
#  * Function: QRfact
#  * -----------------------------------------------------------------
#  * QRfact performs a QR factorization of the Hessenberg matrix H.
#  *
#  * n is the problem size; the matrix H is (n+1) by n.
#  *
#  * h is the (n+1) by n Hessenberg matrix H to be factored. It is
#  * stored row-wise.
#  *
#  * q is an array of length 2*n containing the Givens rotations
#  * computed by this function. A Givens rotation has the form:
#  * | c  -s |
#  * | s   c |.
#  * The components of the Givens rotations are stored in q as
#  * (c, s, c, s, ..., c, s).
#  *
#  * job is a control flag. If job==0, then a new QR factorization
#  * is performed. If job!=0, then it is assumed that the first
#  * n-1 columns of h have already been factored and only the last
#  * column needs to be updated.
#  *
#  * QRfact returns 0 if successful. If a zero is encountered on
#  * the diagonal of the triangular factor R, then QRfact returns
#  * the equation number of the zero entry, where the equations are
#  * numbered from 1, not 0. If QRsol is subsequently called in
#  * this situation, it will return an error because it could not
#  * divide by the zero diagonal entry.
#  * -----------------------------------------------------------------
#
proc QRfact*(n: cint, h: ptr ptr realtype, q: ptr realtype, job: cint): cint {.impsundials_iterativeC.}

#
#  * -----------------------------------------------------------------
#  * Function: QRsol
#  * -----------------------------------------------------------------
#  * QRsol solves the linear least squares problem
#  *
#  * min (b - H*x, b - H*x), x in R^n,
#  *
#  * where H is a Hessenberg matrix, and b is in R^(n+1).
#  * It uses the QR factors of H computed by QRfact.
#  *
#  * n is the problem size; the matrix H is (n+1) by n.
#  *
#  * h is a matrix (computed by QRfact) containing the upper
#  * triangular factor R of the original Hessenberg matrix H.
#  *
#  * q is an array of length 2*n (computed by QRfact) containing
#  * the Givens rotations used to factor H.
#  *
#  * b is the (n+1)-vector appearing in the least squares problem
#  * above.
#  *
#  * On return, b contains the solution x of the least squares
#  * problem, if QRsol was successful.
#  *
#  * QRsol returns a 0 if successful.  Otherwise, a zero was
#  * encountered on the diagonal of the triangular factor R.
#  * In this case, QRsol returns the equation number (numbered
#  * from 1, not 0) of the zero entry.
#  * -----------------------------------------------------------------
#
proc QRsol*(n: cint, h: ptr ptr realtype, q: ptr realtype, b: ptr realtype): cint {.impsundials_iterativeC.}

# Importing /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_matrix.h
# Generated at 2019-07-29T21:21:33+02:00
# Command line:
#   /home/jose/.nimble/pkgs/nimterop-#head/nimterop/toast --preprocess --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/lib64 --pnim --dynlib=libsundials_cvode --nim:/home/jose/.choosenim/toolchains/nim-0.20.2/bin/nim --pluginSourcePath=/tmp/nimterop_170946992310022160.nim /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_matrix.h

{.hint[ConvFromXtoItselfNotNeeded]: off.}

import nimterop/types

#  -----------------------------------------------------------------
#  * Programmer(s): Daniel Reynolds @ SMU
#  *                David Gardner, Carol Woodward, Slaven Peles,
#  *                Cody Balos @ LLNL
#  * -----------------------------------------------------------------
#  * SUNDIALS Copyright Start
#  * Copyright (c) 2002-2019, Lawrence Livermore National Security
#  * and Southern Methodist University.
#  * All rights reserved.
#  *
#  * See the top-level LICENSE and NOTICE files for details.
#  *
#  * SPDX-License-Identifier: BSD-3-Clause
#  * SUNDIALS Copyright End
#  * -----------------------------------------------------------------
#  * This is the header file for a generic matrix package.
#  * It defines the SUNMatrix structure (_generic_SUNMatrix) which
#  * contains the following fields:
#  *   - an implementation-dependent 'content' field which contains
#  *     the description and actual data of the matrix
#  *   - an 'ops' filed which contains a structure listing operations
#  *     acting on such matrices
#  * -----------------------------------------------------------------
#  * This header file contains:
#  *   - enumeration constants for all SUNDIALS-defined matrix types,
#  *     as well as a generic type for user-supplied matrix types,
#  *   - type declarations for the _generic_SUNMatrix and
#  *     _generic_SUNMatrix_Ops structures, as well as references to
#  *     pointers to such structures (SUNMatrix), and
#  *   - prototypes for the matrix functions which operate on
#  *     SUNMatrix objects.
#  * -----------------------------------------------------------------
#  * At a minimum, a particular implementation of a SUNMatrix must
#  * do the following:
#  *   - specify the 'content' field of SUNMatrix,
#  *   - implement the operations on those SUNMatrix objects,
#  *   - provide a constructor routine for new SUNMatrix objects
#  *
#  * Additionally, a SUNMatrix implementation may provide the following:
#  *   - macros to access the underlying SUNMatrix data
#  *   - a routine to print the content of a SUNMatrix
#  * -----------------------------------------------------------------
#  -----------------------------------------------------------------
#  * Implemented SUNMatrix types
#  * -----------------------------------------------------------------
defineEnum(SUNMatrix_ID)

const
  SUNMATRIX_DENSE* = 0.SUNMatrix_ID
  SUNMATRIX_BAND* = 1.SUNMatrix_ID
  SUNMATRIX_SPARSE* = 2.SUNMatrix_ID
  SUNMATRIX_SLUNRLOC* = 3.SUNMatrix_ID
  SUNMATRIX_CUSTOM* = 4.SUNMatrix_ID

#
#  * -----------------------------------------------------------------
#  * IV. SUNMatrix error codes
#  * ---------------------------------------------------------------
#
  SUNMAT_SUCCESS* = 0
  SUNMAT_ILL_INPUT* = -1
  SUNMAT_MEM_FAIL* = -2
  SUNMAT_OPERATION_FAIL* = -3
  SUNMAT_MATVEC_SETUP_REQUIRED* = -4

{.pragma: impsundials_matrix, importc.}
{.pragma: impsundials_matrixC, impsundials_matrix, cdecl, dynlib: libsundials_cvode.}

type

#  -----------------------------------------------------------------
#  * Generic definition of SUNMatrix
#  * -----------------------------------------------------------------
#  Forward reference for pointer to SUNMatrix_Ops object
  SUNMatrix_Ops* {.impsundials_matrix.} = ptr generic_SUNMatrix_Ops

#  Forward reference for pointer to SUNMatrix object
  SUNMatrix* {.impsundials_matrix.} = ptr generic_SUNMatrix

#  Structure containing function pointers to matrix operations
  generic_SUNMatrix_Ops* {.importc: "struct _generic_SUNMatrix_Ops", bycopy.} = object
    getid*: proc(a1: SUNMatrix): SUNMatrix_ID {.cdecl.}
    clone*: proc(a1: SUNMatrix): SUNMatrix {.cdecl.}
    destroy*: proc(a1: SUNMatrix) {.cdecl.}
    zero*: proc(a1: SUNMatrix): cint {.cdecl.}
    copy*: proc(a1: SUNMatrix, a2: SUNMatrix): cint {.cdecl.}
    scaleadd*: proc(a1: realtype, a2: SUNMatrix, a3: SUNMatrix): cint {.cdecl.}
    scaleaddi*: proc(a1: realtype, a2: SUNMatrix): cint {.cdecl.}
    matvecsetup*: proc(a1: SUNMatrix): cint {.cdecl.}
    matvec*: proc(a1: SUNMatrix, a2: N_Vector, a3: N_Vector): cint {.cdecl.}
    space*: proc(a1: SUNMatrix, a2: ptr clong, a3: ptr clong): cint {.cdecl.}

#  A matrix is a structure with an implementation-dependent
#    'content' field, and a pointer to a structure of matrix
#    operations corresponding to that implementation.
  generic_SUNMatrix* {.importc: "struct _generic_SUNMatrix", bycopy.} = object
    content*: pointer
    ops*: SUNMatrix_Ops

#  -----------------------------------------------------------------
#  * Functions exported by SUNMatrix module
#  * -----------------------------------------------------------------
proc SUNMatNewEmpty*(): SUNMatrix {.impsundials_matrixC.}
proc SUNMatFreeEmpty*(A: SUNMatrix) {.impsundials_matrixC.}
proc SUNMatCopyOps*(A: SUNMatrix, B: SUNMatrix): cint {.impsundials_matrixC.}
proc SUNMatGetID*(A: SUNMatrix): SUNMatrix_ID {.impsundials_matrixC.}
proc SUNMatClone*(A: SUNMatrix): SUNMatrix {.impsundials_matrixC.}
proc SUNMatDestroy*(A: SUNMatrix) {.impsundials_matrixC.}
proc SUNMatZero*(A: SUNMatrix): cint {.impsundials_matrixC.}
proc SUNMatCopy*(A: SUNMatrix, B: SUNMatrix): cint {.impsundials_matrixC.}
proc SUNMatScaleAdd*(c: realtype, A: SUNMatrix, B: SUNMatrix): cint {.impsundials_matrixC.}
proc SUNMatScaleAddI*(c: realtype, A: SUNMatrix): cint {.impsundials_matrixC.}
proc SUNMatMatvecSetup*(A: SUNMatrix): cint {.impsundials_matrixC.}
proc SUNMatMatvec*(A: SUNMatrix, x: N_Vector, y: N_Vector): cint {.impsundials_matrixC.}
proc SUNMatSpace*(A: SUNMatrix, lenrw: ptr clong, leniw: ptr clong): cint {.impsundials_matrixC.}

# Importing /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_linearsolver.h
# Generated at 2019-07-29T21:21:33+02:00
# Command line:
#   /home/jose/.nimble/pkgs/nimterop-#head/nimterop/toast --preprocess --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/lib64 --pnim --dynlib=libsundials_cvode --nim:/home/jose/.choosenim/toolchains/nim-0.20.2/bin/nim --pluginSourcePath=/tmp/nimterop_170946992310022160.nim /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sundials/sundials_linearsolver.h

{.hint[ConvFromXtoItselfNotNeeded]: off.}

import nimterop/types

#  -----------------------------------------------------------------
#  * Programmer(s): Daniel Reynolds @ SMU
#  *                David Gardner, Carol Woodward, Slaven Peles @ LLNL
#  * -----------------------------------------------------------------
#  * SUNDIALS Copyright Start
#  * Copyright (c) 2002-2019, Lawrence Livermore National Security
#  * and Southern Methodist University.
#  * All rights reserved.
#  *
#  * See the top-level LICENSE and NOTICE files for details.
#  *
#  * SPDX-License-Identifier: BSD-3-Clause
#  * SUNDIALS Copyright End
#  * -----------------------------------------------------------------
#  * This is the header file for a generic linear solver package.
#  * It defines the SUNLinearSolver structure (_generic_SUNLinearSolver)
#  * which contains the following fields:
#  *   - an implementation-dependent 'content' field which contains
#  *     any internal data required by the solver
#  *   - an 'ops' filed which contains a structure listing operations
#  *     acting on/by such solvers
#  *
#  * We consider both direct linear solvers and iterative linear solvers
#  * as available implementations of this package.  Furthermore, iterative
#  * linear solvers can either use a matrix or be matrix-free.  As a
#  * result of these different solver characteristics, some of the
#  * routines are applicable only to some types of linear solver.
#  * -----------------------------------------------------------------
#  * This header file contains:
#  *   - enumeration constants for all SUNDIALS-defined linear solver
#  *     types, as well as a generic type for user-supplied linear
#  *     solver types,
#  *   - type declarations for the _generic_SUNLinearSolver and
#  *     _generic_SUNLinearSolver_Ops structures, as well as references
#  *     to pointers to such structures (SUNLinearSolver),
#  *   - prototypes for the linear solver functions which operate
#  *     on/by SUNLinearSolver objects, and
#  *   - return codes for SUNLinearSolver objects.
#  * -----------------------------------------------------------------
#  * At a minimum, a particular implementation of a SUNLinearSolver must
#  * do the following:
#  *   - specify the 'content' field of SUNLinearSolver,
#  *   - implement the operations on/by those SUNLinearSolver objects,
#  *   - provide a constructor routine for new SUNLinearSolver objects
#  *
#  * Additionally, a SUNLinearSolver implementation may provide the
#  * following:
#  *   - "Set" routines to control solver-specific parameters/options
#  *   - "Get" routines to access solver-specific performance metrics
#  * -----------------------------------------------------------------
#  -----------------------------------------------------------------
#  * Implemented SUNLinearSolver types:
#  * -----------------------------------------------------------------
defineEnum(SUNLinearSolver_Type)

const
  SUNLINEARSOLVER_DIRECT* = 0.SUNLinearSolver_Type
  SUNLINEARSOLVER_ITERATIVE* = 1.SUNLinearSolver_Type
  SUNLINEARSOLVER_MATRIX_ITERATIVE* = 2.SUNLinearSolver_Type

#  -----------------------------------------------------------------
#  * SUNLinearSolver return values
#  * -----------------------------------------------------------------
  SUNLS_SUCCESS* = 0
  SUNLS_MEM_NULL* = -1
  SUNLS_ILL_INPUT* = -2
  SUNLS_MEM_FAIL* = -3
  SUNLS_ATIMES_FAIL_UNREC* = -4
  SUNLS_PSET_FAIL_UNREC* = -5
  SUNLS_PSOLVE_FAIL_UNREC* = -6
  SUNLS_PACKAGE_FAIL_UNREC* = -7
  SUNLS_GS_FAIL* = -8
  SUNLS_QRSOL_FAIL* = -9
  SUNLS_VECTOROP_ERR* = -10
  SUNLS_RES_REDUCED* = 1
  SUNLS_CONV_FAIL* = 2
  SUNLS_ATIMES_FAIL_REC* = 3
  SUNLS_PSET_FAIL_REC* = 4
  SUNLS_PSOLVE_FAIL_REC* = 5
  SUNLS_PACKAGE_FAIL_REC* = 6
  SUNLS_QRFACT_FAIL* = 7
  SUNLS_LUFACT_FAIL* = 8

{.pragma: impsundials_linearsolver, importc.}
{.pragma: impsundials_linearsolverC, impsundials_linearsolver, cdecl, dynlib: libsundials_cvode.}

type

#  -----------------------------------------------------------------
#  * Generic definition of SUNLinearSolver
#  * -----------------------------------------------------------------
#  Forward reference for pointer to SUNLinearSolver_Ops object
  SUNLinearSolver_Ops* {.impsundials_linearsolver.} = ptr generic_SUNLinearSolver_Ops

#  Forward reference for pointer to SUNLinearSolver object
  SUNLinearSolver* {.impsundials_linearsolver.} = ptr generic_SUNLinearSolver

#  Structure containing function pointers to linear solver operations
  generic_SUNLinearSolver_Ops* {.importc: "struct _generic_SUNLinearSolver_Ops", bycopy.} = object
    gettype*: proc(a1: SUNLinearSolver): SUNLinearSolver_Type {.cdecl.}
    setatimes*: proc(a1: SUNLinearSolver, a2: pointer, a3: ATimesFn): cint {.cdecl.}
    setpreconditioner*: proc(a1: SUNLinearSolver, a2: pointer, a3: PSetupFn, a4: PSolveFn): cint {.cdecl.}
    setscalingvectors*: proc(a1: SUNLinearSolver, a2: N_Vector, a3: N_Vector): cint {.cdecl.}
    initialize*: proc(a1: SUNLinearSolver): cint {.cdecl.}
    setup*: proc(a1: SUNLinearSolver, a2: SUNMatrix): cint {.cdecl.}
    solve*: proc(a1: SUNLinearSolver, a2: SUNMatrix, a3: N_Vector, a4: N_Vector, a5: realtype): cint {.cdecl.}
    numiters*: proc(a1: SUNLinearSolver): cint {.cdecl.}
    resnorm*: proc(a1: SUNLinearSolver): realtype {.cdecl.}
    lastflag*: proc(a1: SUNLinearSolver): clong {.cdecl.}
    space*: proc(a1: SUNLinearSolver, a2: ptr clong, a3: ptr clong): cint {.cdecl.}
    resid*: proc(a1: SUNLinearSolver): N_Vector {.cdecl.}
    free*: proc(a1: SUNLinearSolver): cint {.cdecl.}

#  A linear solver is a structure with an implementation-dependent
#    'content' field, and a pointer to a structure of linear solver
#    operations corresponding to that implementation.
  generic_SUNLinearSolver* {.importc: "struct _generic_SUNLinearSolver", bycopy.} = object
    content*: pointer
    ops*: SUNLinearSolver_Ops

#  -----------------------------------------------------------------
#  * Functions exported by SUNLinearSolver module
#  * -----------------------------------------------------------------
proc SUNLinSolNewEmpty*(): SUNLinearSolver {.impsundials_linearsolverC.}
proc SUNLinSolFreeEmpty*(S: SUNLinearSolver) {.impsundials_linearsolverC.}
proc SUNLinSolGetType*(S: SUNLinearSolver): SUNLinearSolver_Type {.impsundials_linearsolverC.}
proc SUNLinSolSetATimes*(S: SUNLinearSolver, A_data: pointer, ATimes: ATimesFn): cint {.impsundials_linearsolverC.}
proc SUNLinSolSetPreconditioner*(S: SUNLinearSolver, P_data: pointer, Pset: PSetupFn, Psol: PSolveFn): cint {.impsundials_linearsolverC.}
proc SUNLinSolSetScalingVectors*(S: SUNLinearSolver, s1: N_Vector, s2: N_Vector): cint {.impsundials_linearsolverC.}
proc SUNLinSolInitialize*(S: SUNLinearSolver): cint {.impsundials_linearsolverC.}
proc SUNLinSolSetup*(S: SUNLinearSolver, A: SUNMatrix): cint {.impsundials_linearsolverC.}
proc SUNLinSolSolve*(S: SUNLinearSolver, A: SUNMatrix, x: N_Vector, b: N_Vector, tol: realtype): cint {.impsundials_linearsolverC.}
proc SUNLinSolNumIters*(S: SUNLinearSolver): cint {.impsundials_linearsolverC.}
proc SUNLinSolResNorm*(S: SUNLinearSolver): realtype {.impsundials_linearsolverC.}
proc SUNLinSolResid*(S: SUNLinearSolver): N_Vector {.impsundials_linearsolverC.}
proc SUNLinSolLastFlag*(S: SUNLinearSolver): clong {.impsundials_linearsolverC.}
proc SUNLinSolSpace*(S: SUNLinearSolver, lenrwLS: ptr clong, leniwLS: ptr clong): cint {.impsundials_linearsolverC.}
proc SUNLinSolFree*(S: SUNLinearSolver): cint {.impsundials_linearsolverC.}

# Importing /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sunlinsol/sunlinsol_spgmr.h
# Generated at 2019-07-29T21:21:33+02:00
# Command line:
#   /home/jose/.nimble/pkgs/nimterop-#head/nimterop/toast --preprocess --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/lib64 --pnim --dynlib=libsundials_sunlinsolspgmr --nim:/home/jose/.choosenim/toolchains/nim-0.20.2/bin/nim --pluginSourcePath=/tmp/nimterop_170946992310022160.nim /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sunlinsol/sunlinsol_spgmr.h

{.hint[ConvFromXtoItselfNotNeeded]: off.}

import nimterop/types

const

#
#  * -----------------------------------------------------------------
#  * Programmer(s): Daniel Reynolds @ SMU
#  * Based on code sundials_spgmr.h by: Scott D. Cohen,
#  *      Alan C. Hindmarsh and Radu Serban @ LLNL
#  * -----------------------------------------------------------------
#  * SUNDIALS Copyright Start
#  * Copyright (c) 2002-2019, Lawrence Livermore National Security
#  * and Southern Methodist University.
#  * All rights reserved.
#  *
#  * See the top-level LICENSE and NOTICE files for details.
#  *
#  * SPDX-License-Identifier: BSD-3-Clause
#  * SUNDIALS Copyright End
#  * -----------------------------------------------------------------
#  * This is the header file for the SPGMR implementation of the
#  * SUNLINSOL module, SUNLINSOL_SPGMR.  The SPGMR algorithm is based
#  * on the Scaled Preconditioned GMRES (Generalized Minimal Residual)
#  * method.
#  *
#  * Note:
#  *   - The definition of the generic SUNLinearSolver structure can
#  *     be found in the header file sundials_linearsolver.h.
#  * -----------------------------------------------------------------
#
#  Default SPGMR solver parameters
  SUNSPGMR_MAXL_DEFAULT* = 5
  SUNSPGMR_MAXRS_DEFAULT* = 0

{.pragma: impsunlinsol_spgmr, importc.}
{.pragma: impsunlinsol_spgmrC, impsunlinsol_spgmr, cdecl, dynlib: libsundials_sunlinsolspgmr.}

type

#  ----------------------------------------
#  * SPGMR Implementation of SUNLinearSolver
#  * ----------------------------------------
  SUNLinearSolverContent_SPGMR* {.importc: "struct _SUNLinearSolverContent_SPGMR", bycopy.} = object
    maxl*: cint
    pretype*: cint
    gstype*: cint
    max_restarts*: cint
    numiters*: cint
    resnorm*: realtype
    last_flag*: clong
    ATimes*: ATimesFn
    ATData*: pointer
    Psetup*: PSetupFn
    Psolve*: PSolveFn
    PData*: pointer
    s1*: N_Vector
    s2*: N_Vector
    V*: ptr N_Vector
    Hes*: ptr ptr realtype
    givens*: ptr realtype
    xcor*: N_Vector
    yg*: ptr realtype
    vtemp*: N_Vector
    cv*: ptr realtype
    Xv*: ptr N_Vector

#  ---------------------------------------
#  * Exported Functions for SUNLINSOL_SPGMR
#  * ---------------------------------------
proc SUNLinSol_SPGMR*(y: N_Vector, pretype: cint, maxl: cint): SUNLinearSolver {.impsunlinsol_spgmrC.}
proc SUNLinSol_SPGMRSetPrecType*(S: SUNLinearSolver, pretype: cint): cint {.impsunlinsol_spgmrC.}
proc SUNLinSol_SPGMRSetGSType*(S: SUNLinearSolver, gstype: cint): cint {.impsunlinsol_spgmrC.}
proc SUNLinSol_SPGMRSetMaxRestarts*(S: SUNLinearSolver, maxrs: cint): cint {.impsunlinsol_spgmrC.}

#  deprecated
proc SUNSPGMR*(y: N_Vector, pretype: cint, maxl: cint): SUNLinearSolver {.impsunlinsol_spgmrC.}

#  deprecated
proc SUNSPGMRSetPrecType*(S: SUNLinearSolver, pretype: cint): cint {.impsunlinsol_spgmrC.}

#  deprecated
proc SUNSPGMRSetGSType*(S: SUNLinearSolver, gstype: cint): cint {.impsunlinsol_spgmrC.}

#  deprecated
proc SUNSPGMRSetMaxRestarts*(S: SUNLinearSolver, maxrs: cint): cint {.impsunlinsol_spgmrC.}
proc SUNLinSolGetType_SPGMR*(S: SUNLinearSolver): SUNLinearSolver_Type {.impsunlinsol_spgmrC.}
proc SUNLinSolInitialize_SPGMR*(S: SUNLinearSolver): cint {.impsunlinsol_spgmrC.}
proc SUNLinSolSetATimes_SPGMR*(S: SUNLinearSolver, A_data: pointer, ATimes: ATimesFn): cint {.impsunlinsol_spgmrC.}
proc SUNLinSolSetPreconditioner_SPGMR*(S: SUNLinearSolver, P_data: pointer, Pset: PSetupFn, Psol: PSolveFn): cint {.impsunlinsol_spgmrC.}
proc SUNLinSolSetScalingVectors_SPGMR*(S: SUNLinearSolver, s1: N_Vector, s2: N_Vector): cint {.impsunlinsol_spgmrC.}
proc SUNLinSolSetup_SPGMR*(S: SUNLinearSolver, A: SUNMatrix): cint {.impsunlinsol_spgmrC.}
proc SUNLinSolSolve_SPGMR*(S: SUNLinearSolver, A: SUNMatrix, x: N_Vector, b: N_Vector, tol: realtype): cint {.impsunlinsol_spgmrC.}
proc SUNLinSolNumIters_SPGMR*(S: SUNLinearSolver): cint {.impsunlinsol_spgmrC.}
proc SUNLinSolResNorm_SPGMR*(S: SUNLinearSolver): realtype {.impsunlinsol_spgmrC.}
proc SUNLinSolResid_SPGMR*(S: SUNLinearSolver): N_Vector {.impsunlinsol_spgmrC.}
proc SUNLinSolLastFlag_SPGMR*(S: SUNLinearSolver): clong {.impsunlinsol_spgmrC.}
proc SUNLinSolSpace_SPGMR*(S: SUNLinearSolver, lenrwLS: ptr clong, leniwLS: ptr clong): cint {.impsunlinsol_spgmrC.}
proc SUNLinSolFree_SPGMR*(S: SUNLinearSolver): cint {.impsunlinsol_spgmrC.}

# Importing /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sunmatrix/sunmatrix_dense.h
# Generated at 2019-07-29T21:21:34+02:00
# Command line:
#   /home/jose/.nimble/pkgs/nimterop-#head/nimterop/toast --preprocess --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/lib64 --pnim --dynlib=libsundials_sunmatrixdense --nim:/home/jose/.choosenim/toolchains/nim-0.20.2/bin/nim --pluginSourcePath=/tmp/nimterop_170946992310022160.nim /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/sunmatrix/sunmatrix_dense.h

{.hint[ConvFromXtoItselfNotNeeded]: off.}

import nimterop/types

{.pragma: impsunmatrix_dense, importc.}
{.pragma: impsunmatrix_denseC, impsunmatrix_dense, cdecl, dynlib: libsundials_sunmatrixdense.}

type

#
#  * -----------------------------------------------------------------
#  * Programmer(s): Daniel Reynolds @ SMU
#  *                David Gardner @ LLNL
#  * Based on code sundials_direct.h by: Radu Serban @ LLNL
#  * -----------------------------------------------------------------
#  * SUNDIALS Copyright Start
#  * Copyright (c) 2002-2019, Lawrence Livermore National Security
#  * and Southern Methodist University.
#  * All rights reserved.
#  *
#  * See the top-level LICENSE and NOTICE files for details.
#  *
#  * SPDX-License-Identifier: BSD-3-Clause
#  * SUNDIALS Copyright End
#  * -----------------------------------------------------------------
#  * This is the header file for the dense implementation of the
#  * SUNMATRIX module, SUNMATRIX_DENSE.
#  *
#  * Notes:
#  *   - The definition of the generic SUNMatrix structure can be found
#  *     in the header file sundials_matrix.h.
#  *   - The definition of the type 'realtype' can be found in the
#  *     header file sundials_types.h, and it may be changed (at the
#  *     configuration stage) according to the user's needs.
#  *     The sundials_types.h file also contains the definition
#  *     for the type 'booleantype' and 'indextype'.
#  * -----------------------------------------------------------------
#
#  ----------------------------------
#  * Dense implementation of SUNMatrix
#  * ----------------------------------
  SUNMatrixContent_Dense* {.importc: "struct _SUNMatrixContent_Dense", bycopy.} = object
    M*: sunindextype
    N*: sunindextype
    data*: ptr realtype
    ldata*: sunindextype
    cols*: ptr ptr realtype

#  ------------------------------------
#  * Macros for access to SUNMATRIX_DENSE
#  * ------------------------------------
#  ---------------------------------------
#  * Exported Functions for SUNMATRIX_DENSE
#  * ---------------------------------------
proc SUNDenseMatrix*(M: sunindextype, N: sunindextype): SUNMatrix {.impsunmatrix_denseC.}
proc SUNDenseMatrix_Print*(A: SUNMatrix, outfile: ptr FILE) {.impsunmatrix_denseC.}
proc SUNDenseMatrix_Rows*(A: SUNMatrix): sunindextype {.impsunmatrix_denseC.}
proc SUNDenseMatrix_Columns*(A: SUNMatrix): sunindextype {.impsunmatrix_denseC.}
proc SUNDenseMatrix_LData*(A: SUNMatrix): sunindextype {.impsunmatrix_denseC.}
proc SUNDenseMatrix_Data*(A: SUNMatrix): ptr realtype {.impsunmatrix_denseC.}
proc SUNDenseMatrix_Cols*(A: SUNMatrix): ptr ptr realtype {.impsunmatrix_denseC.}
proc SUNDenseMatrix_Column*(A: SUNMatrix, j: sunindextype): ptr realtype {.impsunmatrix_denseC.}
proc SUNMatGetID_Dense*(A: SUNMatrix): SUNMatrix_ID {.impsunmatrix_denseC.}
proc SUNMatClone_Dense*(A: SUNMatrix): SUNMatrix {.impsunmatrix_denseC.}
proc SUNMatDestroy_Dense*(A: SUNMatrix) {.impsunmatrix_denseC.}
proc SUNMatZero_Dense*(A: SUNMatrix): cint {.impsunmatrix_denseC.}
proc SUNMatCopy_Dense*(A: SUNMatrix, B: SUNMatrix): cint {.impsunmatrix_denseC.}
proc SUNMatScaleAdd_Dense*(c: realtype, A: SUNMatrix, B: SUNMatrix): cint {.impsunmatrix_denseC.}
proc SUNMatScaleAddI_Dense*(c: realtype, A: SUNMatrix): cint {.impsunmatrix_denseC.}
proc SUNMatMatvec_Dense*(A: SUNMatrix, x: N_Vector, y: N_Vector): cint {.impsunmatrix_denseC.}
proc SUNMatSpace_Dense*(A: SUNMatrix, lenrw: ptr clong, leniw: ptr clong): cint {.impsunmatrix_denseC.}

# Importing /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/cvode/cvode_ls.h
# Generated at 2019-07-29T21:21:34+02:00
# Command line:
#   /home/jose/.nimble/pkgs/nimterop-#head/nimterop/toast --preprocess --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/lib64 --pnim --dynlib=libsundials_cvode --nim:/home/jose/.choosenim/toolchains/nim-0.20.2/bin/nim --pluginSourcePath=/tmp/nimterop_170946992310022160.nim /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/cvode/cvode_ls.h

{.hint[ConvFromXtoItselfNotNeeded]: off.}

import nimterop/types

const

#  ----------------------------------------------------------------
#  * Programmer(s): Daniel R. Reynolds @ SMU
#  *                Scott D. Cohen, Alan C. Hindmarsh and
#  *                Radu Serban @ LLNL
#  * ----------------------------------------------------------------
#  * SUNDIALS Copyright Start
#  * Copyright (c) 2002-2019, Lawrence Livermore National Security
#  * and Southern Methodist University.
#  * All rights reserved.
#  *
#  * See the top-level LICENSE and NOTICE files for details.
#  *
#  * SPDX-License-Identifier: BSD-3-Clause
#  * SUNDIALS Copyright End
#  * ----------------------------------------------------------------
#  * This is the header file for CVODE's linear solver interface.
#  * ----------------------------------------------------------------
# =================================================================
#   CVLS Constants
#   =================================================================
  CVLS_SUCCESS* = 0
  CVLS_MEM_NULL* = -1
  CVLS_LMEM_NULL* = -2
  CVLS_ILL_INPUT* = -3
  CVLS_MEM_FAIL* = -4
  CVLS_PMEM_NULL* = -5
  CVLS_JACFUNC_UNRECVR* = -6
  CVLS_JACFUNC_RECVR* = -7
  CVLS_SUNMAT_FAIL* = -8
  CVLS_SUNLS_FAIL* = -9

{.pragma: impcvode_ls, importc.}
{.pragma: impcvode_lsC, impcvode_ls, cdecl, dynlib: libsundials_cvode.}

type

# =================================================================
#   CVLS user-supplied function prototypes
#   =================================================================
  CVLsJacFn* {.impcvode_ls.} = proc(t: realtype, y: N_Vector, fy: N_Vector, Jac: SUNMatrix, user_data: pointer, tmp1: N_Vector, tmp2: N_Vector, tmp3: N_Vector): cint {.cdecl.}
  CVLsPrecSetupFn* {.impcvode_ls.} = proc(t: realtype, y: N_Vector, fy: N_Vector, jok: cint, jcurPtr: ptr cint, gamma: realtype, user_data: pointer): cint {.cdecl.}
  CVLsPrecSolveFn* {.impcvode_ls.} = proc(t: realtype, y: N_Vector, fy: N_Vector, r: N_Vector, z: N_Vector, gamma: realtype, delta: realtype, lr: cint, user_data: pointer): cint {.cdecl.}
  CVLsJacTimesSetupFn* {.impcvode_ls.} = proc(t: realtype, y: N_Vector, fy: N_Vector, user_data: pointer): cint {.cdecl.}
  CVLsJacTimesVecFn* {.impcvode_ls.} = proc(v: N_Vector, Jv: N_Vector, t: realtype, y: N_Vector, fy: N_Vector, user_data: pointer, tmp: N_Vector): cint {.cdecl.}
  CVLsLinSysFn* {.impcvode_ls.} = proc(t: realtype, y: N_Vector, fy: N_Vector, A: SUNMatrix, jok: cint, jcur: ptr cint, gamma: realtype, user_data: pointer, tmp1: N_Vector, tmp2: N_Vector, tmp3: N_Vector): cint {.cdecl.}

# =================================================================
#   CVLS Exported functions
#   =================================================================
proc CVodeSetLinearSolver*(cvode_mem: pointer, LS: SUNLinearSolver, A: SUNMatrix): cint {.impcvode_lsC.}

# -----------------------------------------------------------------
#   Optional inputs to the CVLS linear solver interface
#   -----------------------------------------------------------------
proc CVodeSetJacFn*(cvode_mem: pointer, jac: CVLsJacFn): cint {.impcvode_lsC.}
proc CVodeSetMaxStepsBetweenJac*(cvode_mem: pointer, msbj: clong): cint {.impcvode_lsC.}
proc CVodeSetEpsLin*(cvode_mem: pointer, eplifac: realtype): cint {.impcvode_lsC.}
proc CVodeSetPreconditioner*(cvode_mem: pointer, pset: CVLsPrecSetupFn, psolve: CVLsPrecSolveFn): cint {.impcvode_lsC.}
proc CVodeSetJacTimes*(cvode_mem: pointer, jtsetup: CVLsJacTimesSetupFn, jtimes: CVLsJacTimesVecFn): cint {.impcvode_lsC.}
proc CVodeSetLinSysFn*(cvode_mem: pointer, linsys: CVLsLinSysFn): cint {.impcvode_lsC.}

# -----------------------------------------------------------------
#   Optional outputs from the CVLS linear solver interface
#   -----------------------------------------------------------------
proc CVodeGetLinWorkSpace*(cvode_mem: pointer, lenrwLS: ptr clong, leniwLS: ptr clong): cint {.impcvode_lsC.}
proc CVodeGetNumJacEvals*(cvode_mem: pointer, njevals: ptr clong): cint {.impcvode_lsC.}
proc CVodeGetNumPrecEvals*(cvode_mem: pointer, npevals: ptr clong): cint {.impcvode_lsC.}
proc CVodeGetNumPrecSolves*(cvode_mem: pointer, npsolves: ptr clong): cint {.impcvode_lsC.}
proc CVodeGetNumLinIters*(cvode_mem: pointer, nliters: ptr clong): cint {.impcvode_lsC.}
proc CVodeGetNumLinConvFails*(cvode_mem: pointer, nlcfails: ptr clong): cint {.impcvode_lsC.}
proc CVodeGetNumJTSetupEvals*(cvode_mem: pointer, njtsetups: ptr clong): cint {.impcvode_lsC.}
proc CVodeGetNumJtimesEvals*(cvode_mem: pointer, njvevals: ptr clong): cint {.impcvode_lsC.}
proc CVodeGetNumLinRhsEvals*(cvode_mem: pointer, nfevalsLS: ptr clong): cint {.impcvode_lsC.}
proc CVodeGetLastLinFlag*(cvode_mem: pointer, flag: ptr clong): cint {.impcvode_lsC.}
proc CVodeGetLinReturnFlagName*(flag: clong): cstring {.impcvode_lsC.}

# Importing /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/cvode/cvode.h
# Generated at 2019-07-29T21:21:34+02:00
# Command line:
#   /home/jose/.nimble/pkgs/nimterop-#head/nimterop/toast --preprocess --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include --includeDirs+=/home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/lib64 --pnim --dynlib=libsundials_cvode --nim:/home/jose/.choosenim/toolchains/nim-0.20.2/bin/nim --pluginSourcePath=/tmp/nimterop_170946992310022160.nim /home/jose/src/nimlang/nim_sundials/sundials/build/lib/usr/local/include/cvode/cvode.h

{.hint[ConvFromXtoItselfNotNeeded]: off.}

import nimterop/types

const

#  -----------------------------------------------------------------
#  * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh, Radu Serban,
#  *                and Dan Shumaker @ LLNL
#  * -----------------------------------------------------------------
#  * SUNDIALS Copyright Start
#  * Copyright (c) 2002-2019, Lawrence Livermore National Security
#  * and Southern Methodist University.
#  * All rights reserved.
#  *
#  * See the top-level LICENSE and NOTICE files for details.
#  *
#  * SPDX-License-Identifier: BSD-3-Clause
#  * SUNDIALS Copyright End
#  * -----------------------------------------------------------------
#  * This is the header file for the main CVODE integrator.
#  * -----------------------------------------------------------------
#  -----------------
#  * CVODE Constants
#  * -----------------
#  lmm
  CV_ADAMS* = 1
  CV_BDF* = 2

#  itask
  CV_NORMAL* = 1
  CV_ONE_STEP* = 2

#  return values
  CV_SUCCESS* = 0
  CV_TSTOP_RETURN* = 1
  CV_ROOT_RETURN* = 2
  CV_WARNING* = 99
  CV_TOO_MUCH_WORK* = -1
  CV_TOO_MUCH_ACC* = -2
  CV_ERR_FAILURE* = -3
  CV_CONV_FAILURE* = -4
  CV_LINIT_FAIL* = -5
  CV_LSETUP_FAIL* = -6
  CV_LSOLVE_FAIL* = -7
  CV_RHSFUNC_FAIL* = -8
  CV_FIRST_RHSFUNC_ERR* = -9
  CV_REPTD_RHSFUNC_ERR* = -10
  CV_UNREC_RHSFUNC_ERR* = -11
  CV_RTFUNC_FAIL* = -12
  CV_NLS_INIT_FAIL* = -13
  CV_NLS_SETUP_FAIL* = -14
  CV_CONSTR_FAIL* = -15
  CV_MEM_FAIL* = -20
  CV_MEM_NULL* = -21
  CV_ILL_INPUT* = -22
  CV_NO_MALLOC* = -23
  CV_BAD_K* = -24
  CV_BAD_T* = -25
  CV_BAD_DKY* = -26
  CV_TOO_CLOSE* = -27
  CV_VECTOROP_ERR* = -28

{.pragma: impcvode, importc.}
{.pragma: impcvodeC, impcvode, cdecl, dynlib: libsundials_cvode.}

type

#  ------------------------------
#  * User-Supplied Function Types
#  * ------------------------------
  CVRhsFn* {.impcvode.} = proc(t: realtype, y: N_Vector, ydot: N_Vector, user_data: pointer): cint {.cdecl.}
  CVRootFn* {.impcvode.} = proc(t: realtype, y: N_Vector, gout: ptr realtype, user_data: pointer): cint {.cdecl.}
  CVEwtFn* {.impcvode.} = proc(y: N_Vector, ewt: N_Vector, user_data: pointer): cint {.cdecl.}
  CVErrHandlerFn* {.impcvode.} = proc(error_code: cint, module: cstring, function: cstring, msg: cstring, user_data: pointer) {.cdecl.}

#  -------------------
#  * Exported Functions
#  * -------------------
#  Initialization functions
proc CVodeCreate*(lmm: cint): pointer {.impcvodeC.}
proc CVodeInit*(cvode_mem: pointer, f: CVRhsFn, t0: realtype, y0: N_Vector): cint {.impcvodeC.}
proc CVodeReInit*(cvode_mem: pointer, t0: realtype, y0: N_Vector): cint {.impcvodeC.}

#  Tolerance input functions
proc CVodeSStolerances*(cvode_mem: pointer, reltol: realtype, abstol: realtype): cint {.impcvodeC.}
proc CVodeSVtolerances*(cvode_mem: pointer, reltol: realtype, abstol: N_Vector): cint {.impcvodeC.}
proc CVodeWFtolerances*(cvode_mem: pointer, efun: CVEwtFn): cint {.impcvodeC.}

#  Optional input functions
proc CVodeSetErrHandlerFn*(cvode_mem: pointer, ehfun: CVErrHandlerFn, eh_data: pointer): cint {.impcvodeC.}
proc CVodeSetErrFile*(cvode_mem: pointer, errfp: ptr FILE): cint {.impcvodeC.}
proc CVodeSetUserData*(cvode_mem: pointer, user_data: pointer): cint {.impcvodeC.}
proc CVodeSetMaxOrd*(cvode_mem: pointer, maxord: cint): cint {.impcvodeC.}
proc CVodeSetMaxNumSteps*(cvode_mem: pointer, mxsteps: clong): cint {.impcvodeC.}
proc CVodeSetMaxHnilWarns*(cvode_mem: pointer, mxhnil: cint): cint {.impcvodeC.}
proc CVodeSetStabLimDet*(cvode_mem: pointer, stldet: cint): cint {.impcvodeC.}
proc CVodeSetInitStep*(cvode_mem: pointer, hin: realtype): cint {.impcvodeC.}
proc CVodeSetMinStep*(cvode_mem: pointer, hmin: realtype): cint {.impcvodeC.}
proc CVodeSetMaxStep*(cvode_mem: pointer, hmax: realtype): cint {.impcvodeC.}
proc CVodeSetStopTime*(cvode_mem: pointer, tstop: realtype): cint {.impcvodeC.}
proc CVodeSetMaxErrTestFails*(cvode_mem: pointer, maxnef: cint): cint {.impcvodeC.}
proc CVodeSetMaxNonlinIters*(cvode_mem: pointer, maxcor: cint): cint {.impcvodeC.}
proc CVodeSetMaxConvFails*(cvode_mem: pointer, maxncf: cint): cint {.impcvodeC.}
proc CVodeSetNonlinConvCoef*(cvode_mem: pointer, nlscoef: realtype): cint {.impcvodeC.}
proc CVodeSetConstraints*(cvode_mem: pointer, constraints: N_Vector): cint {.impcvodeC.}
proc CVodeSetNonlinearSolver*(cvode_mem: pointer, NLS: SUNNonlinearSolver): cint {.impcvodeC.}

#  Rootfinding initialization function
proc CVodeRootInit*(cvode_mem: pointer, nrtfn: cint, g: CVRootFn): cint {.impcvodeC.}

#  Rootfinding optional input functions
proc CVodeSetRootDirection*(cvode_mem: pointer, rootdir: ptr cint): cint {.impcvodeC.}
proc CVodeSetNoInactiveRootWarn*(cvode_mem: pointer): cint {.impcvodeC.}

#  Solver function
proc CVode*(cvode_mem: pointer, tout: realtype, yout: N_Vector, tret: ptr realtype, itask: cint): cint {.impcvodeC.}

#  Dense output function
proc CVodeGetDky*(cvode_mem: pointer, t: realtype, k: cint, dky: N_Vector): cint {.impcvodeC.}

#  Optional output functions
proc CVodeGetWorkSpace*(cvode_mem: pointer, lenrw: ptr clong, leniw: ptr clong): cint {.impcvodeC.}
proc CVodeGetNumSteps*(cvode_mem: pointer, nsteps: ptr clong): cint {.impcvodeC.}
proc CVodeGetNumRhsEvals*(cvode_mem: pointer, nfevals: ptr clong): cint {.impcvodeC.}
proc CVodeGetNumLinSolvSetups*(cvode_mem: pointer, nlinsetups: ptr clong): cint {.impcvodeC.}
proc CVodeGetNumErrTestFails*(cvode_mem: pointer, netfails: ptr clong): cint {.impcvodeC.}
proc CVodeGetLastOrder*(cvode_mem: pointer, qlast: ptr cint): cint {.impcvodeC.}
proc CVodeGetCurrentOrder*(cvode_mem: pointer, qcur: ptr cint): cint {.impcvodeC.}
proc CVodeGetNumStabLimOrderReds*(cvode_mem: pointer, nslred: ptr clong): cint {.impcvodeC.}
proc CVodeGetActualInitStep*(cvode_mem: pointer, hinused: ptr realtype): cint {.impcvodeC.}
proc CVodeGetLastStep*(cvode_mem: pointer, hlast: ptr realtype): cint {.impcvodeC.}
proc CVodeGetCurrentStep*(cvode_mem: pointer, hcur: ptr realtype): cint {.impcvodeC.}
proc CVodeGetCurrentTime*(cvode_mem: pointer, tcur: ptr realtype): cint {.impcvodeC.}
proc CVodeGetTolScaleFactor*(cvode_mem: pointer, tolsfac: ptr realtype): cint {.impcvodeC.}
proc CVodeGetErrWeights*(cvode_mem: pointer, eweight: N_Vector): cint {.impcvodeC.}
proc CVodeGetEstLocalErrors*(cvode_mem: pointer, ele: N_Vector): cint {.impcvodeC.}
proc CVodeGetNumGEvals*(cvode_mem: pointer, ngevals: ptr clong): cint {.impcvodeC.}
proc CVodeGetRootInfo*(cvode_mem: pointer, rootsfound: ptr cint): cint {.impcvodeC.}
proc CVodeGetIntegratorStats*(cvode_mem: pointer, nsteps: ptr clong, nfevals: ptr clong, nlinsetups: ptr clong, netfails: ptr clong, qlast: ptr cint, qcur: ptr cint, hinused: ptr realtype, hlast: ptr realtype, hcur: ptr realtype, tcur: ptr realtype): cint {.impcvodeC.}
proc CVodeGetNumNonlinSolvIters*(cvode_mem: pointer, nniters: ptr clong): cint {.impcvodeC.}
proc CVodeGetNumNonlinSolvConvFails*(cvode_mem: pointer, nncfails: ptr clong): cint {.impcvodeC.}
proc CVodeGetNonlinSolvStats*(cvode_mem: pointer, nniters: ptr clong, nncfails: ptr clong): cint {.impcvodeC.}
proc CVodeGetReturnFlagName*(flag: clong): cstring {.impcvodeC.}

#  Free function
proc CVodeFree*(cvode_mem: ptr pointer) {.impcvodeC.}
genotrance commented 4 years ago

CVRhsFn is wrapped correctly.

I tried setting up locally but ran into a random issue:

sundials/build/lib/usr/local/lib/libsundials_nvecserial.so:1:1: error: stray ‘\177’ in program

Note that it didn't build into lib64. But they are 64-bit binaries.

libsundials_nvecserial.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked

HugoGranstrom commented 4 years ago

The cmake and make procs work great! 👍 Now, this is the only thing left to make it a working wrapper.

If I understand this correctly this is purely a Nim problem and not a Nimterop one?

genotrance commented 4 years ago

Yes that is correct. In the interim you could also just #include the header with an emit pragma.

HugoGranstrom commented 4 years ago

That sounds like a good solution in the meantime 😄👍 Will it know which dynlib to associate the header to automatically (or perhaps that's not how C works 😅)?

genotrance commented 4 years ago

The dynlib is only for importing the procs whereas what you want is to have structs visible in the generated C. Just emit an include for header2.h and it should do what you want.

HugoGranstrom commented 4 years ago

OK 👍 This worked fine for a part of my project until the headers I imported with cImport started to depend on the headers I included using emit. When I looked at the generated C code it looked like this:

#include "nimbase.h"
#include "C:/Users/elev/code/nimsundials-test/build/include/sundials/sundials_nvector.h"
#include "C:/Users/elev/code/nimsundials-test/build/include/sundials/sundials_types.h"
#include <string.h>
#include "C:/Users/elev/code/nimsundials-test/build/include/sundials/sundials_matrix.h"
#include "C:/Users/elev/code/nimsundials-test/build/include/sundials/sundials_linearsolver.h"
#include "C:/Users/elev/code/nimsundials-test/build/include/cvode/cvode_ls.h"
#include <math.h>
#include "C:/Users/elev/code/nimsundials-test/build/include/sundials/sundials_iterative.h"
.
.
.
typedef N_CDECL_PTR(int, tyProc_He6zTnKd9aM4of5wY0JOZ2Q) (void* cvode_mem, CVRhsFn f, realtype t0, struct _generic_N_Vector* y0);
typedef N_CDECL_PTR(int, tyProc_zKZO8fHF0odL87hND3oVAQ) (void* cvode_mem, realtype reltol, realtype abstol);
typedef N_CDECL_PTR(struct _generic_SUNLinearSolver*, tyProc_HZqNhExJxthFjqGk3tUSwA) (struct _generic_N_Vector* y, int pretype, int maxl);
typedef N_CDECL_PTR(int, tyProc_33A9aAWWcT9bItkfUmolenbQ) (void* cvode_mem, realtype tout, struct _generic_N_Vector* yout, realtype* tret, int itask);
.
.
.
#include "build/include/cvode/cvode.h"
#include "build/include/nvector/nvector_serial.h"
#include "build/include/sunmatrix/sunmatrix_dense.h"
#include "build/include/sunlinsol/sunlinsol_spgmr.h"
#include "build/include/sunlinsol/sunlinsol_dense.h"

The first headers was the ones that was cImported (no dynlib), the second part is the typedefs from those headers and the third part is my emitted headers. The problem is that the typedefs depends on things in the emitted headers. I have tried to place the emit pragma at the top of my code but it puts them down there none the less. I get errors like error: unknown type name 'CVRhsFn' which is because of this.

Thank you for being so helpful 😄 but I think I might as well wait for the Nim bug to be fixed. This seems like a too niche problem to be fixed as it's just a temporary fix.

genotrance commented 4 years ago

I just ran into this myself with the libgit2 wrapper I'm working on - nimgit2.

Good to know that no tricks get the emit content above the typedefs.

Static lib wrapping still works, it is only the dynlib method that is blocked.

cc: @disruptek

genotrance commented 4 years ago

This was actually a nimterop bug - should be fixed in latest #head. Please try and get back.

HugoGranstrom commented 4 years ago

Great! I'll try it out tomorrow and get back to you 😉👍

HugoGranstrom commented 4 years ago

I haven't gotten it to run yet but I'm not getting the errors I used to get at least 👍

I'm getting this error:

could not load: C:\Users\username\code\nimsundials-test\build\lib\libsundials_sunlinsoldense.dll

I have checked and the file does exist. What could be the reasons it couldn't load it? 😅

genotrance commented 4 years ago

Can you share the wrapper? Not generated code.

HugoGranstrom commented 4 years ago

This is the code I'm trying to run. I'm running windows and compiling using MinGw so if you are not doing that as well you might have to change the cmake command. Most of the code is just the high level wrapper, only the top part of the code does Nimterop stuff

import os, strformat

import nimterop/[cimport, paths, git]

const srcDir = currentSourcePath().parentDir()

const buildDir = srcDir/"build"
const libDir = buildDir/"lib"
const inclDir = buildDir/"include"

static:
    #cDebug()
    cDisableCaching()
    gitPull("https://github.com/LLNL/sundials", outdir = srcDir, checkout = "tags/v4.1.0")
    cmake(buildDir, "Makefile", &".. -DCMAKE_INSTALL_PREFIX=\"" & buildDir & "\" -DCMAKE_INSTALL_LIBDIR=\"" & "lib" & "\" -G \"MinGW Makefiles\" -DEXAMPLES_ENABLE_C=\"OFF\"")
    make(buildDir, "cvode.h", "install")

cIncludeDir(inclDir)
cIncludeDir(inclDir/"nvector")
cIncludeDir(inclDir/"sundials")
cIncludeDir(inclDir/"cvode")
cIncludeDir(inclDir/"sunmatrix")
cIncludeDir(inclDir/"sunlinsol")
cIncludeDir(libdir)

cPlugin:
    import strutils
    proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
        if sym.kind == nskType:
            if sym.name == "_N_VectorContent_Serial":
                sym.name = "N_VectorContent_Serial_Base"
        if sym.name == "ModifiedGS":
            sym.name = "cModifiedGS"
        if sym.name == "ClassicalGS":
            sym.name = "cClassicalGS"
        if sym.name == "_SpgmrMemRec":
            sym.name = "cSpgmrMemRec"
        sym.name = sym.name.strip(chars = {'_'})

const
    libsundials_nvecserial = libDir/"libsundials_nvecserial.dll"
    libsundials_cvode = libDir/"libsundials_cvode.dll"
    libsundials_sunlinsolspgmr = libDir/"libsundials_sunlinsolspgmr.dll"
    libsundials_sunmatrixdense = libDir/"libsundials_sunmatrixdense.dll"
    libsundials_sunlinsoldense = libDir/"libsundials_sunlinsoldense.dll"

cImport(inclDir/"sundials/sundials_config.h", dynlib="libsundials_cvode")
cImport(inclDir/"sundials/sundials_types.h")
cImport(inclDir/"sundials/sundials_math.h")

cImport(inclDir/"sundials/sundials_nvector.h")
cImport(inclDir/"nvector/nvector_serial.h", dynlib = "libsundials_nvecserial")

cImport(inclDir/"sundials/sundials_nonlinearsolver.h")
cImport(inclDir/"sundials/sundials_direct.h")
cImport(inclDir/"sundials/sundials_iterative.h")
cImport(inclDir/"sundials/sundials_matrix.h")
cImport(inclDir/"sundials/sundials_linearsolver.h")
cImport(inclDir/"sundials/sundials_band.h")
cImport(inclDir/"sundials/sundials_version.h")

cImport(inclDir/"sunmatrix/sunmatrix_dense.h", dynlib = "libsundials_sunmatrixdense")

cImport(inclDir/"sundials/sundials_dense.h")

cImport(inclDir/"sunlinsol/sunlinsol_spgmr.h", dynlib="libsundials_sunlinsolspgmr")

cImport(inclDir/"cvode/cvode_ls.h", dynlib="libsundials_cvode")
cImport(inclDir/"cvode/cvode_direct.h")
cImport(inclDir/"cvode/cvode_spils.h")
cImport(inclDir/"cvode/cvode_bbdpre.h")
cImport(inclDir/"cvode/cvode_diag.h")
cImport(inclDir/"cvode/cvode_bandpre.h")

cImport(inclDir/"sunlinsol/sunlinsol_dense.h", dynlib="libsundials_sunlinsoldense")

cImport(inclDir/"cvode/cvode.h", dynlib="libsundials_cvode")

template ptr2Array*[T](p: pointer): auto = cast[ptr UncheckedArray[T]](p)
template array2Ptr*[T](arr: openArray[T]): auto = addr(arr[0])

template `->`*(a, b: untyped): untyped =
    a[].b

template NV_CONTENT_S*(v: untyped): untyped = cast[N_VectorContent_Serial](v->content)
template NV_LENGTH_S*(v: untyped): untyped = NV_CONTENT_S(v) -> length
template NV_OWN_DATA_S*(v: untyped): untyped = NV_CONTENT_S(v) -> own_data
template NV_DATA_S*(v: untyped): untyped = NV_CONTENT_S(v) -> data
template NV_Ith_S*(v: untyped, i: sunindextype): untyped = ptr2Array[realtype](NV_DATA_S(v))[i]

type
    NVectorType* = object
        length*: int
        rawVector*: ref[N_Vector]

proc newNVector*(length: int): NVectorType =
    if length <= 0:
        raise newException(ValueError, "NVector length must be greater than 0")
    result.length = length
    result.rawVector = new N_Vector
    result.rawVector[] = N_VNew_Serial(result.length)

# create newNVector(length) and for over arr, NV_Ith_S(result, i) = arr[i] to keep it in memory.
# N_VClone_Serial and loop over it. 
# NVectorArray = ptr2Array[realtype](NV_DATA_S(v))
proc newNVector*(arr: openArray[realtype]): NVectorType =
    if arr.len <= 0:
        raise newException(ValueError, "NVector length must be greater than 0")
    result.length = arr.len
    result.rawVector = new N_Vector
    result.rawVector[] = N_VNew_Serial(result.length)
    for i in 0 ..< result.length:
        NV_Ith_S(result.rawVector[], i) = arr[i]

proc newNVector*(v: N_Vector): NVectorType =
    result = newNVector(NV_LENGTH_S(v).int)
    N_VScale_Serial(1.0, v, result.rawVector[])

proc clone*(v: NVectorType): NVectorType =
    result = newNVector(v.length)
    N_VScale_Serial(1.0, v.rawVector[], result.rawVector[])

proc `[]`*(v: NVectorType, i: int): realtype =
    if v.length <= i:
        raise newException(ValueError, "index i is out of range. `[]`")
    NV_Ith_S(v.rawVector[], i)

proc `[]=`*(v: NVectorType, i: int, c: realtype) =
    if v.length <= i:
        raise newException(ValueError, "index i is out of range. `[]`")
    NV_Ith_S(v.rawVector[], i) = c

proc `$`*(v: NVectorType): string =
    result = "NVector("
    for i in 0 ..< v.length:
        result = result & $v[i] & ", "
    result = result & ")"

proc `@`*(v: NVectorType): seq[realtype] =
    for i in 0 ..< v.length:
        result.add(v[i])

proc `==`*(a, b: NVectorType): bool =
    let length = a.length
    if length != b.length:
        raise newException(ValueError, "NVectors must have same lengths for `==`")
    let aData = ptr2Array[realtype](NV_DATA_S(a.rawVector[]))
    let bData = ptr2Array[realtype](NV_DATA_S(b.rawVector[]))
    for i in 0 ..< length:
        if aData[i] != bData[i]:
            return false
    return true

proc `+`*(a, b: NVectorType): NVectorType =
    if a.length != b.length:
        raise newException(ValueError, "NVector must be of same length for addition")
    result = newNVector(a.length)
    N_VLinearSum_Serial(1.0, a.rawVector[], 1.0, b.rawVector[], result.rawVector[])

proc `+`*(v: NVectorType, c: realtype): NVectorType =
    result = newNVector(v.length)
    N_VAddConst_Serial(v.rawVector[], c, result.rawVector[])

proc `+`*(c: realtype, v: NVectorType): NVectorType =
    result = newNVector(v.length)
    N_VAddConst_Serial(v.rawVector[], c, result.rawVector[])

proc `+=`*(a: var NVectorType, b: NVectorType) =
    if a.length != b.length:
        raise newException(ValueError, "NVector must be of same length for addition")
    N_VLinearSum_Serial(1.0, a.rawVector[], 1.0, b.rawVector[], a.rawVector[])

proc `+=`*(v: var NVectorType, c: realtype) =
    N_VAddConst_Serial(v.rawVector[], c, v.rawVector[])

proc `-`*(a, b: NVectorType): NVectorType =
    if a.length != b.length:
        raise newException(ValueError, "NVector must be of same length for addition")
    result = newNVector(a.length)
    N_VLinearSum_Serial(1.0, a.rawVector[], -1.0, b.rawVector[], result.rawVector[])

proc `-`*(v: NVectorType, c: realtype): NVectorType =
    result = newNVector(v.length)
    N_VAddConst_Serial(v.rawVector[], -c, result.rawVector[])

# TODO
#[ 
proc `-`*(c: realtype, v: NVectorType): NVectorType =
    result = newNVector(v.length)
    N_VAddConst_Serial(v.rawVector[], c, result.rawVector[])
]#

proc `-=`*(a: var NVectorType, b: NVectorType) =
    if a.length != b.length:
        raise newException(ValueError, "NVector must be of same length for addition")
    N_VLinearSum_Serial(1.0, a.rawVector[], -1.0, b.rawVector[], a.rawVector[])

proc `-=`*(v: var NVectorType, c: realtype) =
    N_VAddConst_Serial(v.rawVector[], -c, v.rawVector[])

proc `*`*(v: NVectorType, c: realtype): NVectorType =
    result = newNVector(v.length)
    N_VScale_Serial(c, v.rawVector[], result.rawVector[])
proc `*`*(c: realtype, v: NVectorType): NVectorType =
    result = newNVector(v.length)
    N_VScale_Serial(c, v.rawVector[], result.rawVector[])

template CVodeProc*(name, body: untyped): untyped {.dirty.} =
    proc `name`(t: realtype, y_raw: N_Vector, ydot_raw: N_Vector, user_data: pointer): cint {.cdecl.} =
        let y = newNVector(y_raw)
        var ydot = newNVector(ydot_raw)
        body
        NV_DATA_S(ydot_raw) = NV_DATA_S(ydot.rawVector[])
    proc `name`(t: realtype, y: NVectorType): NVectorType =
        var ydot = newNVector(y.length)
        body
        result = ydot

# tout should be openArray[realtype]
proc CVodeSolve*(f: proc(t: realtype, y_raw: N_Vector, ydot_raw: N_Vector, user_data: pointer): cint {.cdecl.}, y0: NVectorType, t0, tout: realtype, abstol = 1e-8, reltol = 1e-8): NVectorType =
    var cvode_mem = CVodeCreate(CV_ADAMS)
    var A: SUNMatrix = nil #SUNDenseMatrix(neqs, neqs)
    var flag = CVodeInit(cvode_mem, f, t0, y0.rawVector[])
    flag = CVodeSStolerances(cvode_mem, reltol, abstol)
    var LS = SUNLinSol_SPGMR(y0.rawVector[], 0, 0)
    flag = CVodeSetLinearSolver(cvode_mem, LS, A)
    var t = 0.0
    var y = newNVector(y0.length)
    flag = CVode(cvode_mem, tout, y.rawVector[], addr(t), CV_NORMAL)
    CVodeFree(addr(cvode_mem))
    flag = SUNLinSolFree_Dense(LS)
    SUNMatDestroy_Dense(A)
    result = y

echo "\n\n\n\nLet the real testing begin:"
echo "Addition:"
var v1 = newNVector([1.0, 2.0, 3.0])
var v2 = newNVector([4.0, 5.0, 6.0])
var vsum = v1 + v2
N_VPrint_Serial(vsum.rawVector[])
N_VPrint_Serial((1.0 + v1 + 1.0).rawVector[])
echo "Inplace Addition:"
v2 += v1
N_VPrint_Serial(v2.rawVector[])
v2 += 2.2
N_VPrint_Serial(v2.rawVector[])
echo v2 == v1

echo v2
echo v2[2]
echo -1.0 * v2

proc f(t: realtype, y_raw: N_Vector, ydot_raw: N_Vector, user_data: pointer): cint {.cdecl.} =
    let y = newNVector(y_raw)
    var ydot = newNVector(ydot_raw)
    ydot = clone(y)
    NV_DATA_S(ydot_raw) = NV_DATA_S(ydot.rawVector[])
    #NV_Ith_S(ydot_raw, 0) = NV_Ith_S(y_raw, 0)
    #NV_Ith_S(ydot_raw, 1) = NV_Ith_S(y_raw, 1)
    #NV_Ith_S(ydot_raw, 2) = NV_Ith_S(y_raw, 2)

CVodeProc f2:
    #ydot = 1/(t+1) * y
    ydot = y

var cvode_mem: pointer = nil
cvode_mem = CVodeCreate(CV_ADAMS)
var t0 = 0.0
var y0 = newNVector([1.0, 1.0, 1.0])
var A: SUNMatrix = nil#SUNDenseMatrix(3, 3)
let reltol = 1e-8
let abstol = 1e-8
var flag = CVodeInit(cvode_mem, f2, t0, y0.rawVector[])
flag = CVodeSStolerances(cvode_mem, reltol, abstol)
var LS = SUNLinSol_SPGMR(y0.rawVector[], 0, 0)
flag = CVodeSetLinearSolver(cvode_mem, LS, A)
var t: realtype = 0.0
var tout = 1.0
flag = CVode(cvode_mem, tout, y0.rawVector[], addr(t), CV_NORMAL)

import math
var correct = newNVector(@[exp(1.0), exp(1.0), exp(1.0)])
echo "Answer", y0
echo "Error: ", correct - y0
echo "f2: ", f2(10.0, y0)
echo "Seq: ", @y0
CVodeFree(addr(cvode_mem))
flag = SUNLinSolFree_Dense(LS)
SUNMatDestroy_Dense(A)

echo "New supercool function: " , CVodeSolve(f2, newNVector([1.0, 1.0, 1.0]), 0.0, 1.0)

echo "Clone test:"
var dolly = newNVector([1.0, 2.0, 3.0])
echo "Dolly: ", dolly
var dolly2 = clone(dolly)
echo "Dolly2: ", dolly2
dolly += 2.0
echo "Dolly: ", dolly
echo "Dolly2: ", dolly2
dolly2 += 10.0
echo "Dolly: ", dolly
echo "Dolly2: ", dolly2
echo dolly[0]
dolly[0] = 9.9
echo dolly[0]
echo dolly
genotrance commented 4 years ago

I tried this and got the same error. Can you see if cmake really made correct DLLs for Windows?

HugoGranstrom commented 4 years ago

😅 What should I check for?