From f289deb42323f5d90626f0ae769fcd442e31ac57 Mon Sep 17 00:00:00 2001 From: ltimmerman3 Date: Wed, 13 Nov 2024 12:44:37 -0500 Subject: [PATCH] Updating static printing to allow parsing of atomic and net magnetic moment via API. Updating check_inputs to prevent hanging when including invalid inputs on a slurm environment. --- ChangeLog | 9 +++++++++ src/electronicGroundState.c | 27 ++++++++++++++++----------- src/include/initialization.h | 2 +- src/initialization.c | 16 ++++++++++++---- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1478b7b9..e212e7b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,15 @@ -Name -changes +-------------- +Nov 13, 2024 +Name: Lucas Timmerman +Changes: (initialization.c, initialization.h, electronicGroundState.c) +1. Put check_inputs into it's own loop and added a broadcastable exit flag to trigger an exit on all processors +2. Modified printing in static file so that atomic magnetic moments can be read by api. +3. Added net magnetization to the static file +4. Added net magnetization as part of the final outputs in .out file + -------------- Oct 15, 2024 Name: Shashikant Kumar diff --git a/src/electronicGroundState.c b/src/electronicGroundState.c index bf89e01e..bf013af6 100644 --- a/src/electronicGroundState.c +++ b/src/electronicGroundState.c @@ -136,6 +136,9 @@ void Calculate_electronicGroundState(SPARC_OBJ *pSPARC) { if (pSPARC->d3Flag == 1) { fprintf(output_fp,"DFT-D3 correction :%18.10E (Ha)\n", pSPARC->d3Energy[0]); } + if (pSPARC->spin_typ > 0) { + fprintf(output_fp,"Net magnetization :%18.10E (Bohr magneton)\n", pSPARC->netM[0]); + } if (pSPARC->ixc[3] != 0) { fprintf(output_fp,"vdWDF energy :%18.10E (Ha)\n", pSPARC->vdWDFenergy); } @@ -174,17 +177,19 @@ void Calculate_electronicGroundState(SPARC_OBJ *pSPARC) { fprintf(static_fp,"%18.10E %18.10E %18.10E\n", pSPARC->forces[3*i],pSPARC->forces[3*i+1],pSPARC->forces[3*i+2]); } - if (pSPARC->spin_typ == 1) { - fprintf(static_fp, "Atomic magnetization along Z-dir within Radius 2 Bohr: (Bohr magneton)\n"); - for (i = 0; i < pSPARC->n_atom; i++) { - fprintf(static_fp,"%18.10E\n", pSPARC->AtomMag[i]); - } - } - if (pSPARC->spin_typ == 2) { - fprintf(static_fp, "Atomic magnetization along X,Y,Z-dir within Radius 2 Bohr: (Bohr magneton)\n"); - for (i = 0; i < pSPARC->n_atom; i++) { - fprintf(static_fp,"%18.10E %18.10E %18.10E\n", - pSPARC->AtomMag[3*i],pSPARC->AtomMag[3*i+1],pSPARC->AtomMag[3*i+2]); + if (pSPARC->spin_typ > 0) { + fprintf(static_fp, "Net magnetization (Bohr magneton): %18.10E\n", pSPARC->netM[0]); + if (pSPARC->spin_typ == 1) { + fprintf(static_fp, "Atomic magnetization along Z-dir within Radius 2 Bohr (Bohr magneton):\n"); + for (i = 0; i < pSPARC->n_atom; i++) { + fprintf(static_fp,"%18.10E\n", pSPARC->AtomMag[i]); + } + } else if (pSPARC->spin_typ == 2) { + fprintf(static_fp, "Atomic magnetization along X,Y,Z-dir within Radius 2 Bohr (Bohr magneton):\n"); + for (i = 0; i < pSPARC->n_atom; i++) { + fprintf(static_fp,"%18.10E %18.10E %18.10E\n", + pSPARC->AtomMag[3*i],pSPARC->AtomMag[3*i+1],pSPARC->AtomMag[3*i+2]); + } } } fclose(static_fp); diff --git a/src/include/initialization.h b/src/include/initialization.h index c542c78b..a4788aa7 100644 --- a/src/include/initialization.h +++ b/src/include/initialization.h @@ -54,7 +54,7 @@ void SPARC_Input_MPI_create(MPI_Datatype *pSPARC_INPUT_MPI); * @param argc The number of arguments that are passed to the program. * @param argv The array of strings representing command line arguments. */ -void check_inputs(SPARC_INPUT_OBJ *pSPARC_Input, int argc, char *argv[]); +void check_inputs(SPARC_INPUT_OBJ *pSPARC_Input, int argc, char *argv[], int *exit_flag); /** diff --git a/src/initialization.c b/src/initialization.c index 903e9060..79ac95d5 100644 --- a/src/initialization.c +++ b/src/initialization.c @@ -238,19 +238,26 @@ void Initialize(SPARC_OBJ *pSPARC, int argc, char *argv[]) { if (rank == 0) printf("\nCreating SPARC_INPUT_MPI datatype took %.3f ms\n",(t2-t1)*1000); #endif + int exit_flag; if (rank == 0) { #ifdef DEBUG printf("Initializing ...\n"); t1 = MPI_Wtime(); #endif // check input arguments and read filename - check_inputs(&SPARC_Input, argc, argv); + check_inputs(&SPARC_Input, argc, argv, &exit_flag); #ifdef DEBUG t2 = MPI_Wtime(); printf("\nChecking inputs parsed by commandline took %.3f ms\n",(t2-t1)*1000); t1 = MPI_Wtime(); #endif + } + + MPI_Bcast(&exit_flag, 1, MPI_INT, 0, MPI_COMM_WORLD); + if (exit_flag == 1) exit(EXIT_FAILURE); + + if (rank ==0) { set_defaults(&SPARC_Input, pSPARC); // set default values #ifdef DEBUG @@ -496,7 +503,7 @@ void Initialize(SPARC_OBJ *pSPARC, int argc, char *argv[]) { /** * @brief Check input arguments and read filename. */ -void check_inputs(SPARC_INPUT_OBJ *pSPARC_Input, int argc, char *argv[]) { +void check_inputs(SPARC_INPUT_OBJ *pSPARC_Input, int argc, char *argv[], int *exit_flag) { #ifdef DEBUG printf("Checking input arguments parsed by command line.\n"); #endif @@ -529,7 +536,8 @@ void check_inputs(SPARC_INPUT_OBJ *pSPARC_Input, int argc, char *argv[]) { for (i = 1; i < argc-1; i++) { if (strcmp(argv[i],"--help") == 0 || strcmp(argv[i],"-h") == 0) { print_usage(); - exit(EXIT_FAILURE); + *exit_flag = 1; + return; } if (strcmp(argv[i],"-name") == 0) { name_flag = 'Y'; @@ -549,7 +557,7 @@ void check_inputs(SPARC_INPUT_OBJ *pSPARC_Input, int argc, char *argv[]) { if (name_flag != 'Y') { print_usage(); - exit(EXIT_FAILURE); + *exit_flag = 1; } }