Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Towards full Python interface to the C core of CLEED #44

Merged
merged 6 commits into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -213,6 +213,7 @@ dkms.conf

# CMake builds
cmake-build*/
cleedpy/cleed/bin/

# Vscode
.vscode/
59 changes: 44 additions & 15 deletions cleedpy/cleed/src/leed.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include "leed.h"

real ** leed(
struct cryst_str * bulk,
struct cryst_str *over,
struct phs_str *phs_shifts,
int energy_list_size,
real *energy_list,
struct var_str *v_par,
FILE *res_stream
char * par_file,
char * bul_file,
char *res_file
){
struct cryst_str *bulk=NULL;
struct cryst_str *over=NULL;
struct phs_str *phs_shifts=NULL;
struct var_str *v_par=NULL;


struct beams_str * beams_now=NULL;
struct beams_str * beams_set=NULL;
@@ -21,31 +22,57 @@ real ** leed(
int i_layer;
int energy_index;
int n_set;

int energy_list_size;
real *energy_list;
real energy;
real vec[4];

float **iv_curves=NULL;
real **iv_curves=NULL;

mat R_bulk=NULL, R_tot=NULL;
mat Amp=NULL;

mat Tpp=NULL, Tmm=NULL, Rpm=NULL, Rmp=NULL;
mat Tpp_s=NULL, Tmm_s=NULL, Rpm_s=NULL, Rmp_s=NULL;

struct eng_str eng;
struct eng_str *eng=NULL;

FILE *res_stream;

// Read input parameters
printf("HERE %s\n", bul_file);
inp_rdbul_nd(&bulk, &phs_shifts, bul_file);
inp_rdpar(&v_par, &eng, bulk, bul_file);
inp_rdovl_nd(&over, &phs_shifts, bulk, par_file);
inp_showbop(bulk, over, phs_shifts);


// Construct energy list
energy_list_size = (eng->fin - eng->ini)/eng->stp + 1;
energy_list = (real *) malloc(energy_list_size * sizeof(real));
for (energy_index=0; energy_index<energy_list_size; energy_index++)
{
energy_list[energy_index] = eng->ini + energy_index * eng->stp;
}

// Printing stuff
inp_showbop(bulk, over, phs_shifts);

eng.ini = energy_list[0];
eng.stp = energy_list[1] - energy_list[0];
eng.fin = energy_list[energy_list_size-1];

res_stream = fopen(res_file,"w");

out_head(bulk, res_stream);


mk_cg_coef (2*v_par->l_max); // Setting up Clebsh Gordan coefficients as global variables.
mk_ylm_coef(2*v_par->l_max); // Setting up spherical harmonics coefficients as global variables.




/* Generate beams out */
n_set = bm_gen(&beams_all, bulk, v_par, eng.fin);
out_bmlist(&beams_out, beams_all, &eng, res_stream);
n_set = bm_gen(&beams_all, bulk, v_par, eng->fin);
out_bmlist(&beams_out, beams_all, eng, res_stream);


/* Main Energy Loop */
@@ -236,6 +263,8 @@ real ** leed(

} /* end of energy loop */

fclose(res_stream);

return iv_curves;
}

276 changes: 8 additions & 268 deletions cleedpy/cleed/test_cleed.c
Original file line number Diff line number Diff line change
@@ -1,277 +1,17 @@
/*********************************************************************
GH/05.10.00
file contains functions:

main
Main program for LEED calculations (only for bravaislayer)

Changes:

GH/05.10.00 - early return option (-e).


*********************************************************************/

#include <stdio.h>
#include <string.h>

#include "gh_stddef.h"
#include "leed.h"

main(){
// File names
char *bul_file="Ni111_Cu.inp"; // bulk and non-geometrical parameters.
char *par_file="Ni111_Cu.inp"; // overlayer parameters of all parameters (if bul_file does not exist)
char *res_file="leed.res"; // output file containing the LEED intensities

// Calculate LEED intensities
leed(bul_file, par_file, res_file);

/*
#define CONTROL_X
*/
#define CONTROL_FLOW


#define CONTROL_IO
#define CONTROL
#define WARNING
#define ERROR

#define CTR_NORMAL 998
#define CTR_EARLY_RETURN 999

/*======================================================================*/

main(int argc, char *argv[])

/*********************************************************************
Perform a LEED calculation for anisotropic vibrations a general case

INPUT:

DESIGN:

*********************************************************************/
{
struct cryst_str *bulk;
struct cryst_str *over;
struct phs_str *phs_shifts;
struct beam_str *beams_all;
struct beam_str *beams_out;
struct beam_str *beams_now;
struct beam_str *beams_set;
struct var_str *v_par;
struct eng_str *eng;

mat Tpp, Tmm, Rpm, Rmp;
mat Tpp_s, Tmm_s, Rpm_s, Rmp_s;
mat R_bulk, R_tot;
mat Amp;

int ctr_flag;
int i_c, i_arg;
int n_beams_now, n_beams_set;
int i_set, n_set, offset;
int i_layer;

int energy_list_size, energy_index;
real *energy_list;

real energy;
real vec[4];

char linebuffer[STRSZ];

char bul_file[STRSZ]; /* input/output files */
char par_file[STRSZ];
char pro_name[STRSZ];
char res_file[STRSZ];

FILE *pro_stream;
FILE *res_stream;

Tpp = Tmm = Rpm = Rmp = NULL;
Tpp_s = Tmm_s = Rpm_s = Rmp_s = NULL;
R_bulk = R_tot = NULL;
Amp = NULL;

bulk = over = NULL;
phs_shifts = NULL;
beams_all = NULL;
beams_now = NULL;
beams_set = NULL;
beams_out = NULL;
v_par = NULL;
eng = NULL;


/*********************************************************************
Preset parameters (file names) set by arguments
*********************************************************************/

ctr_flag = CTR_NORMAL;

strncpy(bul_file,"---", STRSZ);

strncpy(par_file,"---", STRSZ);
strncpy(res_file,"leed.res", STRSZ);
strncpy(pro_name,"leed.pro", STRSZ);

/*********************************************************************
Decode arguments:

-b <bul_file> - (optional input file) bulk and non-geometrical
parameters.
-i <par_file> - (mandatory input file) overlayer parameters of all
parameters (if bul_file does not exist).
-o <res_file> - (output file) IV output.
*********************************************************************/

for (i_arg = 1; i_arg < argc; i_arg++)
{
if(*argv[i_arg] != '-')
{
#ifdef ERROR
fprintf(STDERR,"*** error (LEED_TEMP):\tsyntax error:\n");
fprintf(STDERR,"\tusage: \tleed -i <par_file> -o <res_file>");
fprintf(STDERR," [-b <bul_file> -e]\n");
#endif
exit(1);
}
else
{

/* Read parameter input file */
if(strncmp(argv[i_arg], "-b", 2) == 0)
{
i_arg++;
strncpy(bul_file, argv[i_arg], STRSZ);
} /* -b */

/* Read parameter input file */
if(strncmp(argv[i_arg], "-i", 2) == 0)
{
i_arg++;
strncpy(par_file, argv[i_arg], STRSZ);
} /* -i */

/* Read and open results file */
if(strncmp(argv[i_arg], "-o", 2) == 0)
{
i_arg++;
strncpy(res_file, argv[i_arg], STRSZ);
if ((res_stream = fopen(res_file,"w")) == NULL)
{
#ifdef ERROR
fprintf(STDERR,
"*** error (LEED_TEMP): could not open output file \"%s\"\n",
res_file);
#endif
exit(1);
}
} /* -o */

/* Read parameter input file */
if(strncmp(argv[i_arg], "-e", 2) == 0)
{
ctr_flag = CTR_EARLY_RETURN;
} /* -e */


} /* else */
} /* for i_arg */

/*********************************************************************
Check arguments:
- check existence of par_file.
- if bul_file is not specified, use par_file instead.
- check existence of res_file.
*********************************************************************/

if(strncmp(par_file, "---", 3) == 0)
{
#ifdef ERROR
fprintf(STDERR,
"*** error (LEED_TEMP): no parameter input file (option -i) specified\n");
#endif
exit(1);
}

if(strncmp(bul_file, "---", 3) == 0)
{
strncpy(bul_file, par_file, STRSZ);
}

if(strncmp(res_file, "leed.res", 8) == 0)
{
#ifdef WARNING
fprintf(STDWAR,
"* warning (LEED_TEMP): no output file (option -o) specified\n");
fprintf(STDWAR,"\toutput will be written to file \"%s\"\n", res_file);
#endif

if ((res_stream = fopen(res_file,"w")) == NULL)
{
#ifdef ERROR
fprintf(STDERR,
"*** error (LEED_TEMP): could not open output file \"%s\"\n",
res_file);
#endif
exit(1);
}
}

/*********************************************************************
Read input parameters
*********************************************************************/

inp_rdbul_nd(&bulk, &phs_shifts, bul_file);
inp_rdpar(&v_par, &eng, bulk, bul_file);
inp_rdovl_nd(&over, &phs_shifts, bulk, par_file);

inp_showbop(bulk, over, phs_shifts);

if( ctr_flag == CTR_EARLY_RETURN )
{
fprintf(STDCTR, "(LEED_TEMP): EARLY RETURN \n");
exit(0);
}

out_head (bulk, res_stream);

/*********************************************************************
Prepare some often used parameters.
*********************************************************************/

mk_cg_coef (2*v_par->l_max);
mk_ylm_coef(2*v_par->l_max);

// Construct energy list
energy_list_size = (eng->fin - eng->ini)/eng->stp + 1;
energy_list = (real *) malloc(energy_list_size * sizeof(real));
for (energy_index=0; energy_index<energy_list_size; energy_index++)
{
energy_list[energy_index] = eng->ini + energy_index * eng->stp;
}

leed(bulk, over, phs_shifts, energy_list_size, energy_list, v_par, res_stream);
printf("Finished leed\n");

#ifdef CONTROL_IO
fprintf(STDCTR, "(LEED): end of energy loop: close files\n");
#endif

fclose(res_stream);

#ifdef CONTROL
fprintf(STDCTR, "\n\n(LEED):\tCORRECT TERMINATION");
#endif

/********************************************
Write cpu time to output
********************************************/

cpu_time(STDCPU,"");

/********************************************
set exit status explicitly
********************************************/

printf("The new code is working\n");
exit(0);

} /* end of main */
}
Loading
Loading