LCOV - code coverage report
Current view: top level - src/grid/common - grid_basis_set.c (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:69d170a) Lines: 45 45 100.0 %
Date: 2024-12-23 07:26:16 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*----------------------------------------------------------------------------*/
       2             : /*  CP2K: A general program to perform molecular dynamics simulations         */
       3             : /*  Copyright 2000-2024 CP2K developers group <https://cp2k.org>              */
       4             : /*                                                                            */
       5             : /*  SPDX-License-Identifier: BSD-3-Clause                                     */
       6             : /*----------------------------------------------------------------------------*/
       7             : 
       8             : #include <assert.h>
       9             : #include <stdlib.h>
      10             : #include <string.h>
      11             : 
      12             : #include "grid_basis_set.h"
      13             : 
      14             : /*******************************************************************************
      15             :  * \brief Allocates a basis set which can be passed to grid_create_task_list.
      16             :  *        See grid_task_list.h for details.
      17             :  * \author Ole Schuett
      18             :  ******************************************************************************/
      19       14477 : void grid_create_basis_set(const int nset, const int nsgf, const int maxco,
      20             :                            const int maxpgf, const int lmin[nset],
      21             :                            const int lmax[nset], const int npgf[nset],
      22             :                            const int nsgf_set[nset], const int first_sgf[nset],
      23       14477 :                            const double sphi[nsgf][maxco],
      24       14477 :                            const double zet[nset][maxpgf],
      25             :                            grid_basis_set **basis_set_out) {
      26             : 
      27       14477 :   grid_basis_set *basis_set = malloc(sizeof(grid_basis_set));
      28       14477 :   assert(basis_set != NULL);
      29             : 
      30       14477 :   basis_set->nset = nset;
      31       14477 :   basis_set->nsgf = nsgf;
      32       14477 :   basis_set->maxco = maxco;
      33       14477 :   basis_set->maxpgf = maxpgf;
      34             : 
      35       14477 :   size_t size = nset * sizeof(int);
      36       14477 :   basis_set->lmin = malloc(size);
      37       14477 :   assert(basis_set->lmin != NULL);
      38       14477 :   memcpy(basis_set->lmin, lmin, size);
      39       14477 :   basis_set->lmax = malloc(size);
      40       14477 :   assert(basis_set->lmax != NULL);
      41       14477 :   memcpy(basis_set->lmax, lmax, size);
      42       14477 :   basis_set->npgf = malloc(size);
      43       14477 :   assert(basis_set->npgf != NULL);
      44       14477 :   memcpy(basis_set->npgf, npgf, size);
      45       14477 :   basis_set->nsgf_set = malloc(size);
      46       14477 :   assert(basis_set->nsgf_set != NULL);
      47       14477 :   memcpy(basis_set->nsgf_set, nsgf_set, size);
      48       14477 :   basis_set->first_sgf = malloc(size);
      49       14477 :   assert(basis_set->first_sgf != NULL);
      50       14477 :   memcpy(basis_set->first_sgf, first_sgf, size);
      51       14477 :   size = nsgf * maxco * sizeof(double);
      52       14477 :   basis_set->sphi = malloc(size);
      53       14477 :   assert(basis_set->sphi != NULL);
      54       14477 :   memcpy(basis_set->sphi, sphi, size);
      55       14477 :   size = nset * maxpgf * sizeof(double);
      56       14477 :   basis_set->zet = malloc(size);
      57       14477 :   assert(basis_set->zet != NULL);
      58       14477 :   memcpy(basis_set->zet, zet, size);
      59             : 
      60       14477 :   *basis_set_out = basis_set;
      61       14477 : }
      62             : 
      63             : /*******************************************************************************
      64             :  * \brief Deallocates given basis set.
      65             :  * \author Ole Schuett
      66             :  ******************************************************************************/
      67       14477 : void grid_free_basis_set(grid_basis_set *basis_set) {
      68       14477 :   free(basis_set->lmin);
      69       14477 :   free(basis_set->lmax);
      70       14477 :   free(basis_set->npgf);
      71       14477 :   free(basis_set->nsgf_set);
      72       14477 :   free(basis_set->first_sgf);
      73       14477 :   free(basis_set->sphi);
      74       14477 :   free(basis_set->zet);
      75       14477 :   free(basis_set);
      76       14477 : }
      77             : 
      78             : // EOF

Generated by: LCOV version 1.15