1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-11-03 20:54:07 +01:00

Add index in files

This commit is contained in:
Anthony Scemama 2021-06-04 14:43:27 +02:00
parent 84cc086228
commit 77f2858548
4 changed files with 48 additions and 27 deletions

View File

@ -56,7 +56,7 @@ AC_PROG_LN_S
## ---------
# Checks for basic header files.
AC_CHECK_HEADERS([fcntl.h inttypes.h stdint.h stdlib.h string.h unistd.h])
AC_CHECK_HEADERS([fcntl.h inttypes.h stdint.h stdbool.h stdlib.h string.h unistd.h])
### HDF5

View File

@ -49,11 +49,12 @@ typedef int32_t trexio_exit_code;
#include <pthread.h>
#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "trexio.h"
#include "trexio_s.h"
#include "trexio_private.h"
#include "trexio_s.h"
#include "trexio_text.h"
#include "trexio_hdf5.h"
/*
@ -70,6 +71,7 @@ typedef int32_t trexio_exit_code;
#include "trexio.h"
#include <pthread.h>
#include <assert.h>
#include <stdbool.h>
#+end_src
* Coding conventions
@ -421,11 +423,12 @@ typedef struct trexio_s trexio_t;
#+begin_src c :tangle prefix_s_front.h
struct trexio_s {
char* file_name;
char file_name[TREXIO_MAX_FILENAME_LENGTH];
pthread_mutex_t thread_lock;
back_end_t back_end;
char mode;
char padding[7]; /* Ensures the proper alignment of back ends */
bool one_based;
char padding[6]; /* Ensures the proper alignment of back ends */
};
#+end_src
** Polymorphism of the file handle
@ -458,11 +461,13 @@ struct trexio_back_end_s {
output:
~trexio_t~ file handle
Note: the ~file_name~ in TEXT back end actually corresponds to the name of the folder where ~.txt~
data files are stored. The actual name of each ~.txt~ file corresponds to the group name provided in
~trex.config~ (e.g. ~nucleus.txt~ for nuclei-related data).
These names are populated by the generator.py (i.e. they are hard-coded), which is why the user
should tend to avoid renaming the ~.txt~ data files.
Note: the ~file_name~ in TEXT back end actually corresponds to the
name of the directory where ~.txt~ data files are stored. The
actual name of each ~.txt~ file corresponds to the group name
provided in ~trex.config~ (e.g. ~nucleus.txt~ for nuclei-related
data). These names are populated by the generator.py (i.e. they
are hard-coded), which is why the user should tend to avoid
renaming the ~.txt~ data files.
#+begin_src c :tangle prefix_front.h :exports none
trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t back_end);
@ -509,16 +514,15 @@ trexio_open(const char* file_name, const char mode,
/* Data for the parent type */
result->file_name = CALLOC(TREXIO_MAX_FILENAME_LENGTH, char);
strncpy(result->file_name, file_name, TREXIO_MAX_FILENAME_LENGTH);
if (result->file_name[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') {
free(result->file_name);
free(result);
return NULL;
}
result->back_end = back_end;
result->mode = mode;
result->one_based = false; // Need to be flipped in Fortran interface
int irc = pthread_mutex_init ( &(result->thread_lock), NULL);
assert (irc == 0);
@ -545,7 +549,6 @@ trexio_open(const char* file_name, const char mode,
}
if (rc != TREXIO_SUCCESS) {
free(result->file_name);
free(result);
return NULL;
}
@ -571,7 +574,6 @@ trexio_open(const char* file_name, const char mode,
}
if (rc != TREXIO_SUCCESS) {
free(result->file_name);
free(result);
return NULL;
}
@ -591,6 +593,25 @@ interface
end interface
#+end_src
Because arrays are zero-based in Fortran, we need to set a flag to
know if we need to shift by 1 arrays of indices.
#+begin_src c :tangle prefix_front.h :exports none
trexio_exit_code trexio_set_one_based(trexio_t* file);
#+end_src
#+begin_src c :tangle prefix_front.c
trexio_exit_code trexio_set_one_based(trexio_t* file)
{
if (file == NULL)
return TREXIO_FILE_ERROR;
file->one_based = true;
return TREXIO_SUCCESS;
}
#+end_src
** File closing
~trexio_close~ closes an existing ~trexio_t~ file.
@ -634,7 +655,6 @@ trexio_close (trexio_t* file)
}
if (rc != TREXIO_SUCCESS) {
FREE(file->file_name);
FREE(file);
return rc;
}
@ -661,8 +681,6 @@ trexio_close (trexio_t* file)
/* Terminate front end */
FREE(file->file_name);
int irc = pthread_mutex_destroy( &(file->thread_lock) );
free(file);

View File

@ -39,11 +39,11 @@
"basis": {
"type" : [ "str" , [] ]
, "shell_num" : [ "int" , [] ]
, "shell_center" : [ "int" , [ "basis.shell_num" ] ]
, "shell_center" : [ "index", [ "basis.shell_num" ] ]
, "shell_ang_mom" : [ "int" , [ "basis.shell_num" ] ]
, "shell_prim_num" : [ "int" , [ "basis.shell_num" ] ]
, "shell_factor" : [ "float", [ "basis.shell_num" ] ]
, "prim_index" : [ "int" , [ "basis.shell_num" ] ]
, "prim_index" : [ "index", [ "basis.shell_num" ] ]
, "prim_num" : [ "int" , [] ]
, "exponent" : [ "float", [ "basis.prim_num" ] ]
, "coefficient" : [ "float", [ "basis.prim_num" ] ]
@ -53,7 +53,7 @@
"ao": {
"cartesian" : [ "int" , [] ]
, "num" : [ "int" , [] ]
, "shell" : [ "int" , [ "ao.num" ] ]
, "shell" : [ "index", [ "ao.num" ] ]
, "normalization" : [ "float", [ "ao.num" ] ]
} ,

View File

@ -7,6 +7,10 @@ column-major order (as in Fortran), and the ordering of the dimensions
is reversed in the produces JSON configuration file as the library is
written in C.
In Fortran, the arrays are 1-based and in most other languages the
arrays are 0-base. Hence, we introduce the ~index~ type which is an
1-based ~int~ in the Fortran interface and 0-based otherwise.
#+begin_src python :tangle trex.json
{
#+end_src
@ -195,11 +199,11 @@ written in C.
#+NAME: basis
| ~type~ | ~str~ | | Type of basis set: "Gaussian" or "Slater" |
| ~shell_num~ | ~int~ | | Total Number of shells |
| ~shell_center~ | ~int~ | ~(basis.shell_num)~ | Nucleus on which the shell is centered ($A$) |
| ~shell_center~ | ~index~ | ~(basis.shell_num)~ | Nucleus on which the shell is centered ($A$) |
| ~shell_ang_mom~ | ~int~ | ~(basis.shell_num)~ | Angular momentum ~0:S, 1:P, 2:D, ...~ |
| ~shell_prim_num~ | ~int~ | ~(basis.shell_num)~ | Number of primitives in the shell ($N_{\text{prim}}$) |
| ~shell_factor~ | ~float~ | ~(basis.shell_num)~ | Normalization factor of the shell ($\mathcal{N}_s$) |
| ~prim_index~ | ~int~ | ~(basis.shell_num)~ | Index of the first primitive in the complete list |
| ~prim_index~ | ~index~ | ~(basis.shell_num)~ | Index of the first primitive in the complete list |
| ~prim_num~ | ~int~ | | Total number of primitives |
| ~exponent~ | ~float~ | ~(basis.prim_num)~ | Exponents of the primitives ($\gamma_{ks}) |
| ~coefficient~ | ~float~ | ~(basis.prim_num)~ | Coefficients of the primitives ($a_{ks}$) |
@ -213,11 +217,11 @@ written in C.
"basis": {
"type" : [ "str" , [] ]
, "shell_num" : [ "int" , [] ]
, "shell_center" : [ "int" , [ "basis.shell_num" ] ]
, "shell_center" : [ "index", [ "basis.shell_num" ] ]
, "shell_ang_mom" : [ "int" , [ "basis.shell_num" ] ]
, "shell_prim_num" : [ "int" , [ "basis.shell_num" ] ]
, "shell_factor" : [ "float", [ "basis.shell_num" ] ]
, "prim_index" : [ "int" , [ "basis.shell_num" ] ]
, "prim_index" : [ "index", [ "basis.shell_num" ] ]
, "prim_num" : [ "int" , [] ]
, "exponent" : [ "float", [ "basis.prim_num" ] ]
, "coefficient" : [ "float", [ "basis.prim_num" ] ]
@ -250,8 +254,7 @@ written in C.
\chi_i (\mathbf{r}) = \mathcal{N}_i\, P_{\eta(i)}(\mathbf{r})\, R_{\theta(i)} (\mathbf{r})
\]
where $i$ is the atomic orbital index,
$P$ encodes for either the
where $i$ is the atomic orbital index, $P$ encodes for either the
polynomials or the spherical harmonics, $\theta(i)$ returns the
shell on which the AO is expanded, and $\eta(i)$ denotes which
angular function is chosen.
@ -273,7 +276,7 @@ written in C.
#+NAME: ao
| ~cartesian~ | ~int~ | | ~1~: true, ~0~: false |
| ~num~ | ~int~ | | Total number of atomic orbitals |
| ~shell~ | ~int~ | ~(ao.num)~ | basis set shell for each AO |
| ~shell~ | ~index~ | ~(ao.num)~ | basis set shell for each AO |
| ~normalization~ | ~float~ | ~(ao.num)~ | Normalization factors |
#+CALL: json(data=ao, title="ao")
@ -284,7 +287,7 @@ written in C.
"ao": {
"cartesian" : [ "int" , [] ]
, "num" : [ "int" , [] ]
, "shell" : [ "int" , [ "ao.num" ] ]
, "shell" : [ "index", [ "ao.num" ] ]
, "normalization" : [ "float", [ "ao.num" ] ]
} ,
#+end_src