Fix Funcfl reference to avoid segfaults

Signed-off-by: Rafael Ravedutti <rafaelravedutti@gmail.com>
This commit is contained in:
Rafael Ravedutti 2021-10-26 01:40:02 +02:00
parent 40ddc9ad50
commit 99d6a4bdd8
3 changed files with 37 additions and 14 deletions

View File

@ -1,3 +1,25 @@
/*
* =======================================================================================
*
* Author: Jan Eitzinger (je), jan.eitzinger@fau.de
* Copyright (c) 2020 RRZE, University Erlangen-Nuremberg
*
* This file is part of MD-Bench.
*
* MD-Bench is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MD-Bench is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with MD-Bench. If not, see <https://www.gnu.org/licenses/>.
* =======================================================================================
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -12,19 +34,20 @@
#define MAXLINE 4096 #define MAXLINE 4096
#endif #endif
void initEam(Eam* eam, const char *input_file, int ntypes) { void initEam(Eam* eam, const char* input_file, int ntypes) {
eam->nmax = 0; eam->nmax = 0;
eam->fp = NULL; eam->fp = NULL;
eam->ntypes = ntypes; eam->ntypes = ntypes;
eam->cutforcesq = (MD_FLOAT *) allocate(ALIGNMENT, ntypes * ntypes * sizeof(MD_FLOAT)); eam->cutforcesq = (MD_FLOAT *) allocate(ALIGNMENT, ntypes * ntypes * sizeof(MD_FLOAT));
coeff(eam, input_file); coeff(eam, input_file);
init_style(eam);
} }
void coeff(Eam* eam, const char* arg) { void coeff(Eam* eam, const char* arg) {
read_file(eam->file, arg); read_file(&eam->file, arg);
int n = strlen(arg) + 1; int n = strlen(arg) + 1;
int ntypes = eam->ntypes; int ntypes = eam->ntypes;
double cutmax = eam->file->cut; double cutmax = eam->file.cut;
for(int i=0; i<ntypes*ntypes; i++) for(int i=0; i<ntypes*ntypes; i++)
eam->cutforcesq[i] = cutmax * cutmax; eam->cutforcesq[i] = cutmax * cutmax;
} }
@ -75,7 +98,7 @@ void file2array(Eam* eam) {
double rmax, rhomax; double rmax, rhomax;
eam->dr = eam->drho = rmax = rhomax = 0.0; eam->dr = eam->drho = rmax = rhomax = 0.0;
active = 0; active = 0;
Funcfl* file = eam->file; Funcfl* file = &eam->file;
eam->dr = MAX(eam->dr, file->dr); eam->dr = MAX(eam->dr, file->dr);
eam->drho = MAX(eam->drho, file->drho); eam->drho = MAX(eam->drho, file->drho);
rmax = MAX(rmax, (file->nr - 1) * file->dr); rmax = MAX(rmax, (file->nr - 1) * file->dr);
@ -156,8 +179,8 @@ void file2array(Eam* eam) {
// create a z2r array for each file against other files, only for I >= J // create a z2r array for each file against other files, only for I >= J
// interpolate zri and zrj to a single grid and cutoff // interpolate zri and zrj to a single grid and cutoff
double zri, zrj; double zri, zrj;
Funcfl* ifile = eam->file; Funcfl* ifile = &eam->file;
Funcfl* jfile = eam->file; Funcfl* jfile = &eam->file;
for(m = 1; m <= eam->nr; m++) { for(m = 1; m <= eam->nr; m++) {
r = (m - 1) * eam->dr; r = (m - 1) * eam->dr;

View File

@ -139,17 +139,17 @@ double computeForceEam(Eam* eam, Atom *atom, Neighbor *neighbor, Stats *stats, i
// hence embed' = Fi(sum rho_ij) rhojp + Fj(sum rho_ji) rhoip // hence embed' = Fi(sum rho_ij) rhojp + Fj(sum rho_ji) rhoip
MD_FLOAT rhoip = (rhor_spline[type_ij * nr_tot + m * 7 + 0] * p + MD_FLOAT rhoip = (rhor_spline[type_ij * nr_tot + m * 7 + 0] * p +
rhor_spline[type_ij * nr_tot + m * 7 + 1]) * p + rhor_spline[type_ij * nr_tot + m * 7 + 1]) * p +
rhor_spline[type_ij * nr_tot + m * 7 + 2]; rhor_spline[type_ij * nr_tot + m * 7 + 2];
MD_FLOAT z2p = (z2r_spline[type_ij * nr_tot + m * 7 + 0] * p + MD_FLOAT z2p = (z2r_spline[type_ij * nr_tot + m * 7 + 0] * p +
z2r_spline[type_ij * nr_tot + m * 7 + 1]) * p + z2r_spline[type_ij * nr_tot + m * 7 + 1]) * p +
z2r_spline[type_ij * nr_tot + m * 7 + 2]; z2r_spline[type_ij * nr_tot + m * 7 + 2];
MD_FLOAT z2 = ((z2r_spline[type_ij * nr_tot + m * 7 + 3] * p + MD_FLOAT z2 = ((z2r_spline[type_ij * nr_tot + m * 7 + 3] * p +
z2r_spline[type_ij * nr_tot + m * 7 + 4]) * p + z2r_spline[type_ij * nr_tot + m * 7 + 4]) * p +
z2r_spline[type_ij * nr_tot + m * 7 + 5]) * p + z2r_spline[type_ij * nr_tot + m * 7 + 5]) * p +
z2r_spline[type_ij * nr_tot + m * 7 + 6]; z2r_spline[type_ij * nr_tot + m * 7 + 6];
MD_FLOAT recip = 1.0 / r; MD_FLOAT recip = 1.0 / r;
MD_FLOAT phi = z2 * recip; MD_FLOAT phi = z2 * recip;

View File

@ -43,7 +43,7 @@ typedef struct {
MD_FLOAT *frho, *rhor, *z2r; MD_FLOAT *frho, *rhor, *z2r;
MD_FLOAT *rhor_spline, *frho_spline, *z2r_spline; MD_FLOAT *rhor_spline, *frho_spline, *z2r_spline;
MD_FLOAT *cutforcesq; MD_FLOAT *cutforcesq;
Funcfl* file; Funcfl file;
} Eam; } Eam;
void initEam(Eam* eam, const char* input_file, int ntypes); void initEam(Eam* eam, const char* input_file, int ntypes);