1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-07-18 08:53:47 +02:00
qmckl/src/qmckl_context.org

507 lines
16 KiB
Org Mode
Raw Normal View History

2020-11-05 15:34:58 +01:00
** Context
2020-10-14 01:43:13 +02:00
2020-11-05 15:34:58 +01:00
This file is written in C because it is more natural to express the context in
C than in Fortran.
2020-10-16 19:42:12 +02:00
2020-11-05 15:34:58 +01:00
2 files are produced:
- a source file : =qmckl_context.c=
- a test file : =test_qmckl_context.c=
2020-10-14 01:43:13 +02:00
2020-11-05 15:34:58 +01:00
*** Headers :noexport:
#+BEGIN_SRC C :tangle qmckl_context.c
2020-10-16 23:56:22 +02:00
#include "qmckl.h"
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-16 19:42:12 +02:00
2020-11-05 15:34:58 +01:00
#+BEGIN_SRC C :tangle test_qmckl_context.c
2020-10-22 00:50:07 +02:00
#include "qmckl.h"
#include "munit.h"
MunitResult test_qmckl_context() {
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-14 00:52:50 +02:00
2020-11-05 15:34:58 +01:00
*** Context
2020-10-14 01:43:13 +02:00
2020-11-05 15:34:58 +01:00
The context variable is a handle for the state of the library, and
is stored in the following data structure, which can't be seen
outside of the library. To simplify compatibility with other
languages, the pointer to the internal data structure is converted
into a 64-bit signed integer, defined in the =qmckl_context= type.
A value of 0 for the context is equivalent to a =NULL= pointer.
2020-10-14 00:52:50 +02:00
2020-11-05 15:34:58 +01:00
#+BEGIN_SRC C :comments org :tangle qmckl.h
#+END_SRC
2020-11-05 15:27:25 +01:00
2020-11-05 15:34:58 +01:00
***** Source
2020-11-05 15:27:25 +01:00
2020-11-05 15:34:58 +01:00
The tag is used internally to check if the memory domain pointed by
a pointer is a valid context.
2020-11-05 15:27:25 +01:00
2020-11-05 15:34:58 +01:00
#+BEGIN_SRC C :comments org :tangle qmckl_context.c
2020-10-16 13:58:05 +02:00
typedef struct qmckl_context_struct {
struct qmckl_context_struct * prev;
2020-10-22 00:50:07 +02:00
uint32_t tag;
int32_t precision;
int32_t range;
2020-10-14 00:52:50 +02:00
} qmckl_context_struct;
#define VALID_TAG 0xBEEFFACE
#define INVALID_TAG 0xDEADBEEF
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-22 00:50:07 +02:00
2020-11-05 15:34:58 +01:00
***** Test :noexport:
#+BEGIN_SRC C :tangle test_qmckl_context.c
2020-11-05 15:27:25 +01:00
qmckl_context context;
qmckl_context new_context;
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-16 19:52:11 +02:00
2020-10-22 00:50:07 +02:00
2020-11-05 15:34:58 +01:00
**** =qmckl_context_check=
2020-10-22 00:50:07 +02:00
2020-11-05 15:34:58 +01:00
Checks if the domain pointed by the pointer is a valid context.
Returns the input =qmckl_context= if the context is valid, 0 otherwise.
2020-11-05 15:34:58 +01:00
#+BEGIN_SRC C :comments org :tangle qmckl.h
2020-10-22 00:50:07 +02:00
qmckl_context qmckl_context_check(const qmckl_context context) ;
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-22 00:50:07 +02:00
2020-11-05 15:34:58 +01:00
***** Source
#+BEGIN_SRC C :tangle qmckl_context.c
2020-10-22 00:50:07 +02:00
qmckl_context qmckl_context_check(const qmckl_context context) {
if (context == (qmckl_context) 0) return (qmckl_context) 0;
2020-10-14 00:52:50 +02:00
2020-11-05 00:46:19 +01:00
const qmckl_context_struct * ctx = (qmckl_context_struct*) context;
if (ctx->tag != VALID_TAG) return (qmckl_context) 0;
2020-10-22 00:50:07 +02:00
return context;
}
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-22 00:50:07 +02:00
2020-11-05 15:34:58 +01:00
**** =qmckl_context_create=
2020-10-14 00:52:50 +02:00
2020-11-05 15:34:58 +01:00
To create a new context, use =qmckl_context_create()=.
- On success, returns a pointer to a context using the =qmckl_context= type
- Returns 0 upon failure to allocate the internal data structure
2020-11-05 15:34:58 +01:00
#+BEGIN_SRC C :comments org :tangle qmckl.h
2020-10-14 00:52:50 +02:00
qmckl_context qmckl_context_create();
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-14 00:52:50 +02:00
2020-11-05 15:34:58 +01:00
***** Source
#+BEGIN_SRC C :tangle qmckl_context.c
2020-10-14 00:52:50 +02:00
qmckl_context qmckl_context_create() {
2020-11-05 00:46:19 +01:00
qmckl_context_struct* context =
(qmckl_context_struct*) qmckl_malloc ((qmckl_context) 0, sizeof(qmckl_context_struct));
2020-10-14 00:52:50 +02:00
if (context == NULL) {
return (qmckl_context) 0;
}
context->prev = NULL;
context->precision = QMCKL_DEFAULT_PRECISION;
context->range = QMCKL_DEFAULT_RANGE;
context->tag = VALID_TAG;
2020-10-14 00:52:50 +02:00
return (qmckl_context) context;
}
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-22 00:50:07 +02:00
2020-11-05 15:34:58 +01:00
***** Fortran interface
#+BEGIN_SRC f90 :tangle qmckl_f.f90
2020-11-05 00:46:19 +01:00
interface
integer (c_int64_t) function qmckl_context_create() bind(C)
use, intrinsic :: iso_c_binding
end function qmckl_context_create
end interface
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 00:46:19 +01:00
2020-11-05 15:34:58 +01:00
***** Test :noexport:
#+BEGIN_SRC C :comments link :tangle test_qmckl_context.c
2020-11-05 15:27:25 +01:00
context = qmckl_context_create();
munit_assert_int64( context, !=, (qmckl_context) 0);
munit_assert_int64( qmckl_context_check(context), ==, context);
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-14 01:43:13 +02:00
2020-11-05 15:34:58 +01:00
**** =qmckl_context_copy=
2020-10-14 00:52:50 +02:00
2020-11-05 15:34:58 +01:00
This function makes a shallow copy of the current context.
- Copying the 0-valued context returns 0
- On success, returns a pointer to the new context using the =qmckl_context= type
- Returns 0 upon failure to allocate the internal data structure
for the new context
2020-10-16 19:42:12 +02:00
2020-11-05 15:34:58 +01:00
#+BEGIN_SRC C :comments org :tangle qmckl.h
qmckl_context qmckl_context_copy(const qmckl_context context);
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-14 00:52:50 +02:00
2020-11-05 15:34:58 +01:00
***** Source
#+BEGIN_SRC C :tangle qmckl_context.c
qmckl_context qmckl_context_copy(const qmckl_context context) {
2020-10-14 00:52:50 +02:00
2020-11-05 00:46:19 +01:00
const qmckl_context checked_context = qmckl_context_check(context);
if (checked_context == (qmckl_context) 0) {
2020-10-16 19:42:12 +02:00
return (qmckl_context) 0;
}
2020-11-05 00:46:19 +01:00
qmckl_context_struct* old_context = (qmckl_context_struct*) checked_context;
qmckl_context_struct* new_context =
(qmckl_context_struct*) qmckl_malloc (context, sizeof(qmckl_context_struct));
2020-10-14 00:52:50 +02:00
if (new_context == NULL) {
return (qmckl_context) 0;
}
new_context->prev = old_context;
2020-10-14 01:43:13 +02:00
new_context->precision = old_context->precision;
2020-10-14 00:52:50 +02:00
new_context->range = old_context->range;
new_context->tag = VALID_TAG;
2020-10-14 00:52:50 +02:00
return (qmckl_context) new_context;
}
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-14 01:43:13 +02:00
2020-11-05 15:34:58 +01:00
***** Fortran interface
#+BEGIN_SRC f90 :tangle qmckl_f.f90
2020-11-05 00:46:19 +01:00
interface
integer (c_int64_t) function qmckl_context_copy(context) bind(C)
use, intrinsic :: iso_c_binding
integer (c_int64_t), intent(in), value :: context
end function qmckl_context_copy
end interface
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 00:46:19 +01:00
2020-11-05 15:34:58 +01:00
***** Test :noexport:
#+BEGIN_SRC C :comments link :tangle test_qmckl_context.c
2020-11-05 15:27:25 +01:00
new_context = qmckl_context_copy(context);
munit_assert_int64(new_context, !=, (qmckl_context) 0);
munit_assert_int64(new_context, !=, context);
munit_assert_int64(qmckl_context_check(new_context), ==, new_context);
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 15:34:58 +01:00
**** =qmckl_context_previous=
2020-10-22 00:50:07 +02:00
2020-11-05 15:34:58 +01:00
Returns the previous context
- On success, returns the ancestor of the current context
- Returns 0 for the initial context
- Returns 0 for the 0-valued context
2020-11-05 15:34:58 +01:00
#+BEGIN_SRC C :comments org :tangle qmckl.h
2020-10-16 19:42:12 +02:00
qmckl_context qmckl_context_previous(const qmckl_context context);
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 15:34:58 +01:00
***** Source
#+BEGIN_SRC C :tangle qmckl_context.c
2020-10-16 19:42:12 +02:00
qmckl_context qmckl_context_previous(const qmckl_context context) {
2020-11-05 00:46:19 +01:00
const qmckl_context checked_context = qmckl_context_check(context);
if (checked_context == (qmckl_context) 0) {
2020-10-16 19:42:12 +02:00
return (qmckl_context) 0;
}
2020-11-05 00:46:19 +01:00
const qmckl_context_struct* ctx = (qmckl_context_struct*) checked_context;
return qmckl_context_check((qmckl_context) ctx->prev);
2020-10-16 19:42:12 +02:00
}
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-16 19:42:12 +02:00
2020-11-05 15:34:58 +01:00
***** Fortran interface
#+BEGIN_SRC f90 :tangle qmckl_f.f90
2020-11-05 00:46:19 +01:00
interface
integer (c_int64_t) function qmckl_context_previous(context) bind(C)
use, intrinsic :: iso_c_binding
integer (c_int64_t), intent(in), value :: context
end function qmckl_context_previous
end interface
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 00:46:19 +01:00
2020-11-05 15:34:58 +01:00
***** Test :noexport:
#+BEGIN_SRC C :comments link :tangle test_qmckl_context.c
2020-11-05 15:27:25 +01:00
munit_assert_int64(qmckl_context_previous(new_context), !=, (qmckl_context) 0);
munit_assert_int64(qmckl_context_previous(new_context), ==, context);
munit_assert_int64(qmckl_context_previous(context), ==, (qmckl_context) 0);
munit_assert_int64(qmckl_context_previous((qmckl_context) 0), ==, (qmckl_context) 0);
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-16 19:42:12 +02:00
2020-11-05 15:34:58 +01:00
**** =qmckl_context_destroy=
2020-10-22 00:50:07 +02:00
2020-11-05 15:34:58 +01:00
Destroys the current context, leaving the ancestors untouched.
- Succeeds if the current context is properly destroyed
- Fails otherwise
- Fails if the 0-valued context is given in argument
- Fails if the the pointer is not a valid context
2020-10-22 00:50:07 +02:00
2020-11-05 15:34:58 +01:00
#+BEGIN_SRC C :comments org :tangle qmckl.h
qmckl_exit_code qmckl_context_destroy(qmckl_context context);
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-16 19:42:12 +02:00
2020-11-05 15:34:58 +01:00
***** Source
#+BEGIN_SRC C :tangle qmckl_context.c
2020-11-05 00:46:19 +01:00
qmckl_exit_code qmckl_context_destroy(const qmckl_context context) {
2020-10-22 00:50:07 +02:00
2020-11-05 00:46:19 +01:00
const qmckl_context checked_context = qmckl_context_check(context);
if (checked_context == (qmckl_context) 0) return QMCKL_FAILURE;
2020-10-16 19:42:12 +02:00
2020-11-05 00:46:19 +01:00
qmckl_context_struct* ctx = (qmckl_context_struct*) context;
if (ctx == NULL) return QMCKL_FAILURE;
ctx->tag = INVALID_TAG;
2020-10-16 23:56:22 +02:00
qmckl_free(ctx);
2020-10-16 19:42:12 +02:00
return QMCKL_SUCCESS;
}
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-14 00:52:50 +02:00
2020-11-05 15:34:58 +01:00
***** Fortran interface
#+BEGIN_SRC f90 :tangle qmckl_f.f90
2020-11-05 00:46:19 +01:00
interface
integer (c_int32_t) function qmckl_context_destroy(context) bind(C)
use, intrinsic :: iso_c_binding
integer (c_int64_t), intent(in), value :: context
end function qmckl_context_destroy
end interface
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 00:46:19 +01:00
2020-11-05 15:34:58 +01:00
***** Test :noexport:
#+BEGIN_SRC C :tangle test_qmckl_context.c
2020-11-05 15:27:25 +01:00
munit_assert_int64(qmckl_context_check(new_context), ==, new_context);
munit_assert_int64(new_context, !=, (qmckl_context) 0);
munit_assert_int32(qmckl_context_destroy(new_context), ==, QMCKL_SUCCESS);
munit_assert_int64(qmckl_context_check(new_context), !=, new_context);
munit_assert_int64(qmckl_context_check(new_context), ==, (qmckl_context) 0);
munit_assert_int64(qmckl_context_destroy((qmckl_context) 0), ==, QMCKL_FAILURE);
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-16 19:42:12 +02:00
2020-10-22 00:50:07 +02:00
2020-11-05 15:34:58 +01:00
*** Precision
2020-10-14 00:52:50 +02:00
2020-11-05 15:34:58 +01:00
The following functions set and get the expected required precision
and range. =precision= should be an integer between 2 and 53, and
=range= should be an integer between 2 and 11.
2020-10-16 13:58:05 +02:00
2020-11-05 15:34:58 +01:00
The setter functions functions return a new context as a 64-bit integer.
The getter functions return the value, as a 32-bit integer.
The update functions return =QMCKL_SUCCESS= or =QMCKL_FAILURE=.
2020-10-14 00:52:50 +02:00
2020-11-05 15:34:58 +01:00
**** =qmckl_context_update_precision=
Modifies the parameter for the numerical precision in a given context.
#+BEGIN_SRC C :comments org :tangle qmckl.h
2020-10-22 00:50:07 +02:00
qmckl_exit_code qmckl_context_update_precision(const qmckl_context context, const int precision);
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-14 00:52:50 +02:00
2020-11-05 15:34:58 +01:00
***** Source
#+BEGIN_SRC C :tangle qmckl_context.c
2020-10-22 00:50:07 +02:00
qmckl_exit_code qmckl_context_update_precision(const qmckl_context context, const int precision) {
2020-10-14 00:52:50 +02:00
2020-10-16 13:58:05 +02:00
if (precision < 2) return QMCKL_FAILURE;
if (precision > 53) return QMCKL_FAILURE;
2020-11-05 00:46:19 +01:00
qmckl_context_struct* ctx = (qmckl_context_struct*) context;
2020-10-16 13:58:05 +02:00
if (ctx == NULL) return QMCKL_FAILURE;
2020-10-14 00:52:50 +02:00
ctx->precision = precision;
2020-10-16 13:58:05 +02:00
return QMCKL_SUCCESS;
}
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-16 13:58:05 +02:00
2020-11-05 15:34:58 +01:00
***** Fortran interface
#+BEGIN_SRC f90 :tangle qmckl_f.f90
2020-11-05 00:46:19 +01:00
interface
integer (c_int32_t) function qmckl_context_update_precision(context, precision) bind(C)
use, intrinsic :: iso_c_binding
integer (c_int64_t), intent(in), value :: context
integer (c_int32_t), intent(in), value :: precision
end function qmckl_context_update_precision
end interface
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 00:46:19 +01:00
2020-11-05 15:34:58 +01:00
***** TODO Tests :noexport:
**** =qmckl_context_update_range=
Modifies the parameter for the numerical range in a given context.
#+BEGIN_SRC C :comments org :tangle qmckl.h
2020-10-22 00:50:07 +02:00
qmckl_exit_code qmckl_context_update_range(const qmckl_context context, const int range);
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-22 00:50:07 +02:00
2020-11-05 15:34:58 +01:00
***** Source
#+BEGIN_SRC C :tangle qmckl_context.c
2020-10-22 00:50:07 +02:00
qmckl_exit_code qmckl_context_update_range(const qmckl_context context, const int range) {
2020-10-16 13:58:05 +02:00
if (range < 2) return QMCKL_FAILURE;
if (range > 11) return QMCKL_FAILURE;
2020-11-05 00:46:19 +01:00
qmckl_context_struct* ctx = (qmckl_context_struct*) context;
2020-10-16 13:58:05 +02:00
if (ctx == NULL) return QMCKL_FAILURE;
ctx->range = range;
return QMCKL_SUCCESS;
}
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-16 13:58:05 +02:00
2020-11-05 15:34:58 +01:00
***** Fortran interface
#+BEGIN_SRC f90 :tangle qmckl_f.f90
2020-11-05 00:46:19 +01:00
interface
integer (c_int32_t) function qmckl_context_update_range(context, range) bind(C)
use, intrinsic :: iso_c_binding
integer (c_int64_t), intent(in), value :: context
integer (c_int32_t), intent(in), value :: range
end function qmckl_context_update_range
end interface
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 00:46:19 +01:00
2020-11-05 15:34:58 +01:00
***** TODO Tests :noexport:
**** =qmckl_context_set_precision=
Returns a copy of the context with a different precision parameter.
#+BEGIN_SRC C :comments or :tangle qmckl.h
2020-10-22 00:50:07 +02:00
qmckl_context qmckl_context_set_precision(const qmckl_context context, const int precision);
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-16 13:58:05 +02:00
2020-11-05 15:34:58 +01:00
***** Source
#+BEGIN_SRC C :tangle qmckl_context.c
2020-10-16 13:58:05 +02:00
qmckl_context qmckl_context_set_precision(const qmckl_context context, const int precision) {
2020-11-05 00:46:19 +01:00
qmckl_context new_context = qmckl_context_copy(context);
2020-10-16 13:58:05 +02:00
if (new_context == 0) return 0;
if (qmckl_context_update_precision(context, precision) == QMCKL_FAILURE) return 0;
return new_context;
2020-10-14 00:52:50 +02:00
}
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-14 00:52:50 +02:00
2020-11-05 15:34:58 +01:00
***** Fortran interface
#+BEGIN_SRC f90 :tangle qmckl_f.f90
2020-11-05 00:46:19 +01:00
interface
integer (c_int32_t) function qmckl_context_set_precision(context, precision) bind(C)
use, intrinsic :: iso_c_binding
integer (c_int64_t), intent(in), value :: context
integer (c_int32_t), intent(in), value :: precision
end function qmckl_context_set_precision
end interface
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 00:46:19 +01:00
2020-11-05 15:34:58 +01:00
***** TODO Tests :noexport:
**** =qmckl_context_set_range=
Returns a copy of the context with a different precision parameter.
#+BEGIN_SRC C :comments org :tangle qmckl.h
2020-10-22 00:50:07 +02:00
qmckl_context qmckl_context_set_range(const qmckl_context context, const int range);
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-14 00:52:50 +02:00
2020-11-05 15:34:58 +01:00
***** Source
#+BEGIN_SRC C :tangle qmckl_context.c
2020-10-22 00:50:07 +02:00
qmckl_context qmckl_context_set_range(const qmckl_context context, const int range) {
2020-11-05 00:46:19 +01:00
qmckl_context new_context = qmckl_context_copy(context);
2020-10-16 13:58:05 +02:00
if (new_context == 0) return 0;
2020-10-14 00:52:50 +02:00
2020-10-16 13:58:05 +02:00
if (qmckl_context_update_range(context, range) == QMCKL_FAILURE) return 0;
return new_context;
2020-10-14 00:52:50 +02:00
}
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 15:34:58 +01:00
***** Fortran interface
#+BEGIN_SRC f90 :tangle qmckl_f.f90
2020-11-05 00:46:19 +01:00
interface
integer (c_int32_t) function qmckl_context_set_range(context, range) bind(C)
use, intrinsic :: iso_c_binding
integer (c_int64_t), intent(in), value :: context
integer (c_int32_t), intent(in), value :: range
end function qmckl_context_set_range
end interface
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 00:46:19 +01:00
2020-11-05 15:34:58 +01:00
***** TODO Tests :noexport:
2020-10-22 01:24:14 +02:00
2020-11-05 15:34:58 +01:00
**** =qmckl_context_get_precision=
Returns the value of the numerical precision in the context
#+BEGIN_SRC C :comments org :tangle qmckl.h
2020-11-05 00:46:19 +01:00
int32_t qmckl_context_get_precision(const qmckl_context context);
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 15:34:58 +01:00
***** Source
#+BEGIN_SRC C :tangle qmckl_context.c
int qmckl_context_get_precision(const qmckl_context context) {
2020-11-05 00:46:19 +01:00
const qmckl_context_struct* ctx = (qmckl_context_struct*) context;
return ctx->precision;
}
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 15:34:58 +01:00
***** Fortran interface
#+BEGIN_SRC f90 :tangle qmckl_f.f90
2020-11-05 00:46:19 +01:00
interface
integer (c_int32_t) function qmckl_context_get_precision(context) bind(C)
use, intrinsic :: iso_c_binding
integer (c_int64_t), intent(in), value :: context
end function qmckl_context_get_precision
end interface
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 00:46:19 +01:00
2020-11-05 15:34:58 +01:00
***** TODO Tests :noexport:
**** =qmckl_context_get_range=
Returns the value of the numerical range in the context
#+BEGIN_SRC C :comments org :tangle qmckl.h
2020-11-05 00:46:19 +01:00
int32_t qmckl_context_get_range(const qmckl_context context);
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 15:34:58 +01:00
***** Source
#+BEGIN_SRC C :tangle qmckl_context.c
int qmckl_context_get_range(const qmckl_context context) {
2020-11-05 00:46:19 +01:00
const qmckl_context_struct* ctx = (qmckl_context_struct*) context;
return ctx->range;
}
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-14 00:52:50 +02:00
2020-11-05 15:34:58 +01:00
***** Fortran interface
#+BEGIN_SRC f90 :tangle qmckl_f.f90
2020-11-05 00:46:19 +01:00
interface
integer (c_int32_t) function qmckl_context_get_range(context) bind(C)
use, intrinsic :: iso_c_binding
integer (c_int64_t), intent(in), value :: context
end function qmckl_context_get_range
end interface
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 00:46:19 +01:00
2020-11-05 15:34:58 +01:00
***** TODO Tests :noexport:
2020-11-05 00:46:19 +01:00
2020-11-05 15:34:58 +01:00
**** =qmckl_context_get_epsilon=
2020-11-06 12:10:20 +01:00
Returns $\epsilon = 2^{1-n}$ where =n= is the precision
2020-11-05 15:34:58 +01:00
#+BEGIN_SRC C :comments org :tangle qmckl.h
2020-11-05 00:46:19 +01:00
double qmckl_context_get_epsilon(const qmckl_context context);
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 00:46:19 +01:00
2020-11-05 15:34:58 +01:00
***** Source
#+BEGIN_SRC C :tangle qmckl_context.c
2020-11-05 00:46:19 +01:00
double qmckl_context_get_epsilon(const qmckl_context context) {
const qmckl_context_struct* ctx = (qmckl_context_struct*) context;
2020-11-06 12:10:20 +01:00
return pow(2.0,(double) 1-ctx->precision);
2020-11-05 00:46:19 +01:00
}
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 00:46:19 +01:00
2020-11-05 15:34:58 +01:00
***** Fortran interface
#+BEGIN_SRC f90 :tangle qmckl_f.f90
2020-11-05 00:46:19 +01:00
interface
real (c_double) function qmckl_context_get_epsilon(context) bind(C)
use, intrinsic :: iso_c_binding
integer (c_int64_t), intent(in), value :: context
end function qmckl_context_get_epsilon
end interface
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-11-05 00:46:19 +01:00
2020-11-05 15:34:58 +01:00
***** TODO Tests :noexport:
2020-10-22 00:50:07 +02:00
2020-11-05 15:34:58 +01:00
*** Info about the molecular system
2020-10-30 16:22:29 +01:00
2020-11-05 15:34:58 +01:00
**** TODO =qmckl_context_set_nucl_coord=
**** TODO =qmckl_context_set_nucl_charge=
**** TODO =qmckl_context_set_elec_num=
2020-10-16 13:58:05 +02:00
2020-11-05 15:34:58 +01:00
*** End of files :noexport:
2020-10-16 19:42:12 +02:00
2020-11-05 15:34:58 +01:00
***** Test
#+BEGIN_SRC C :comments link :tangle test_qmckl_context.c
2020-11-05 15:27:25 +01:00
return MUNIT_OK;
2020-10-22 00:50:07 +02:00
}
2020-11-05 15:34:58 +01:00
#+END_SRC
2020-10-16 13:58:05 +02:00
2020-11-05 15:27:25 +01:00
2020-11-05 15:34:58 +01:00
# -*- mode: org -*-
# vim: syntax=c