Fix Funcfl reference to avoid segfaults
Signed-off-by: Rafael Ravedutti <rafaelravedutti@gmail.com>
This commit is contained in:
parent
40ddc9ad50
commit
99d6a4bdd8
@ -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 <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -12,19 +34,20 @@
|
||||
#define MAXLINE 4096
|
||||
#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->fp = NULL;
|
||||
eam->ntypes = ntypes;
|
||||
eam->cutforcesq = (MD_FLOAT *) allocate(ALIGNMENT, ntypes * ntypes * sizeof(MD_FLOAT));
|
||||
coeff(eam, input_file);
|
||||
init_style(eam);
|
||||
}
|
||||
|
||||
void coeff(Eam* eam, const char* arg) {
|
||||
read_file(eam->file, arg);
|
||||
read_file(&eam->file, arg);
|
||||
int n = strlen(arg) + 1;
|
||||
int ntypes = eam->ntypes;
|
||||
double cutmax = eam->file->cut;
|
||||
double cutmax = eam->file.cut;
|
||||
for(int i=0; i<ntypes*ntypes; i++)
|
||||
eam->cutforcesq[i] = cutmax * cutmax;
|
||||
}
|
||||
@ -75,7 +98,7 @@ void file2array(Eam* eam) {
|
||||
double rmax, rhomax;
|
||||
eam->dr = eam->drho = rmax = rhomax = 0.0;
|
||||
active = 0;
|
||||
Funcfl* file = eam->file;
|
||||
Funcfl* file = &eam->file;
|
||||
eam->dr = MAX(eam->dr, file->dr);
|
||||
eam->drho = MAX(eam->drho, file->drho);
|
||||
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
|
||||
// interpolate zri and zrj to a single grid and cutoff
|
||||
double zri, zrj;
|
||||
Funcfl* ifile = eam->file;
|
||||
Funcfl* jfile = eam->file;
|
||||
Funcfl* ifile = &eam->file;
|
||||
Funcfl* jfile = &eam->file;
|
||||
|
||||
for(m = 1; m <= eam->nr; m++) {
|
||||
r = (m - 1) * eam->dr;
|
||||
|
@ -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
|
||||
|
||||
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 + 2];
|
||||
rhor_spline[type_ij * nr_tot + m * 7 + 1]) * p +
|
||||
rhor_spline[type_ij * nr_tot + m * 7 + 2];
|
||||
|
||||
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 + 2];
|
||||
z2r_spline[type_ij * nr_tot + m * 7 + 1]) * p +
|
||||
z2r_spline[type_ij * nr_tot + m * 7 + 2];
|
||||
|
||||
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 + 5]) * p +
|
||||
z2r_spline[type_ij * nr_tot + m * 7 + 6];
|
||||
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 + 6];
|
||||
|
||||
MD_FLOAT recip = 1.0 / r;
|
||||
MD_FLOAT phi = z2 * recip;
|
||||
|
@ -43,7 +43,7 @@ typedef struct {
|
||||
MD_FLOAT *frho, *rhor, *z2r;
|
||||
MD_FLOAT *rhor_spline, *frho_spline, *z2r_spline;
|
||||
MD_FLOAT *cutforcesq;
|
||||
Funcfl* file;
|
||||
Funcfl file;
|
||||
} Eam;
|
||||
|
||||
void initEam(Eam* eam, const char* input_file, int ntypes);
|
||||
|
Loading…
Reference in New Issue
Block a user