From 2f7b7a18646a7623bac538ca2a14ee39acf679a0 Mon Sep 17 00:00:00 2001 From: Kevin Date: Tue, 24 Dec 2024 19:30:39 +0000 Subject: [PATCH] Code quality updates --- src/colloids.c | 6 ++++-- src/fe_electro.c | 9 ++++++--- src/field.c | 4 +++- src/field_grad.c | 10 +++++----- src/io_aggregator.c | 4 ++-- src/io_impl_mpio.c | 2 +- src/io_metadata.c | 2 +- src/lb_model.c | 8 ++++---- src/map.c | 10 +++++----- src/noise.c | 4 ++-- src/phi_force_stress.c | 2 +- src/psi.c | 36 ++++++++++++++++++------------------ src/stencil_d3q19.c | 9 +++++---- src/stencil_d3q27.c | 9 +++++---- src/stencil_d3q7.c | 9 +++++---- src/wall.c | 17 +++++++++-------- 16 files changed, 76 insertions(+), 65 deletions(-) diff --git a/src/colloids.c b/src/colloids.c index cc72f5011..008563a09 100644 --- a/src/colloids.c +++ b/src/colloids.c @@ -109,8 +109,8 @@ __host__ void colloids_info_free(colloids_info_t * info) { colloids_info_cell_list_clean(info); free(info->clist); - if (info->map_old) free(info->map_old); - if (info->map_new) free(info->map_new); + free(info->map_old); + free(info->map_new); if (info->target != info) tdpAssert(tdpFree(info->target)); @@ -175,6 +175,8 @@ __host__ int colloids_info_recreate(int newcell[3], colloids_info_t ** pinfo) { * * colloids_memcpy * + * FIXME: flag is unused + * *****************************************************************************/ __host__ int colloids_memcpy(colloids_info_t * info, int flag) { diff --git a/src/fe_electro.c b/src/fe_electro.c index 58ce03b2f..ac50ff73b 100644 --- a/src/fe_electro.c +++ b/src/fe_electro.c @@ -66,8 +66,9 @@ static fe_vt_t fe_electro_hvt = { (fe_hvector_ft) NULL, (fe_htensor_ft) NULL, (fe_htensor_v_ft) NULL, - (fe_htensor_v_ft) NULL, - (fe_htensor_v_ft) NULL + (fe_stress_v_ft) NULL, + (fe_stress_v_ft) NULL, + (fe_stress_v_ft) NULL }; static __constant__ fe_vt_t fe_electro_dvt = { @@ -158,7 +159,7 @@ __host__ int fe_electro_free(fe_electro_t * fe) { tdpAssert( tdpGetDeviceCount(&ndevice) ); if (ndevice > 0) tdpAssert(tdpFree(fe->target)); - if (fe->mu_ref) free(fe->mu_ref); + free(fe->mu_ref); free(fe); return 0; @@ -263,6 +264,8 @@ int fe_electro_mu(fe_electro_t * fe, int index, double * mu) { * This is a dummy which just returns zero, as an implementation is * required. Physically, there is no solvation chemical potential. * + * FIXME + * ****************************************************************************/ __host__ diff --git a/src/field.c b/src/field.c index ad16de026..17cd9f285 100644 --- a/src/field.c +++ b/src/field.c @@ -168,7 +168,7 @@ __host__ int field_free(field_t * obj) { tdpAssert( tdpFree(obj->target) ); } - if (obj->data) free(obj->data); + free(obj->data); field_halo_free(&obj->h); @@ -1682,6 +1682,8 @@ int field_io_write(field_t * field, int timestep, io_event_t * event) { * * field_io_read * + * FIXME io_event is unused + * *****************************************************************************/ int field_io_read(field_t * field, int timestep, io_event_t * event) { diff --git a/src/field_grad.c b/src/field_grad.c index 456f70a28..e5b660d74 100644 --- a/src/field_grad.c +++ b/src/field_grad.c @@ -298,11 +298,11 @@ __host__ void field_grad_free(field_grad_t * obj) { tdpAssert( tdpFree(obj->target) ); } - if (obj->grad) free(obj->grad); - if (obj->delsq) free(obj->delsq); - if (obj->grad_delsq) free(obj->grad_delsq); - if (obj->delsq_delsq) free(obj->delsq_delsq); - if (obj->d_ab) free(obj->d_ab); + free(obj->grad); + free(obj->delsq); + free(obj->grad_delsq); + free(obj->delsq_delsq); + free(obj->d_ab); obj->field = NULL; free(obj); diff --git a/src/io_aggregator.c b/src/io_aggregator.c index ab3c1ea94..74464ec25 100644 --- a/src/io_aggregator.c +++ b/src/io_aggregator.c @@ -8,7 +8,7 @@ * Edinburgh Soft Matter and Statistical Physics Group and * Edinburgh Parallel Computing Centre * - * (c) 2022 The University of Edinburgh + * (c) 2022-2024 The University of Edinburgh * * Kevin Stratford (kevin@epcc.ed.ac.uk) * @@ -43,7 +43,7 @@ int io_aggregator_create(io_element_t el, cs_limits_t lim, return 0; err: - if (newaggr) free(newaggr); + free(newaggr); return -1; } diff --git a/src/io_impl_mpio.c b/src/io_impl_mpio.c index 0303e9a51..62c21743a 100644 --- a/src/io_impl_mpio.c +++ b/src/io_impl_mpio.c @@ -57,7 +57,7 @@ int io_impl_mpio_create(const io_metadata_t * metadata, return 0; err: - if (mpio) free(mpio); + free(mpio); return -1; } diff --git a/src/io_metadata.c b/src/io_metadata.c index 3e186930a..4d390d68b 100644 --- a/src/io_metadata.c +++ b/src/io_metadata.c @@ -58,7 +58,7 @@ int io_metadata_create(cs_t * cs, err: - if (meta) free(meta); + free(meta); return -1; } diff --git a/src/lb_model.c b/src/lb_model.c index 7c1301e71..78db39af8 100644 --- a/src/lb_model.c +++ b/src/lb_model.c @@ -8,7 +8,7 @@ * Edinburgh Soft Matter and Statistical Physics Group and * Edinburgh Parallel Computing Centre * - * (c) 2021-2022 The University of Edinburgh + * (c) 2021-2024 The University of Edinburgh * * Contributing authors: * Kevin Stratford (kevin@epcc.ed.ac.uk) @@ -108,9 +108,9 @@ int lb_model_free(lb_model_t * model) { free(model->ma); } - if (model->na) free(model->na); - if (model->cv) free(model->cv); - if (model->wv) free(model->wv); + free(model->na); + free(model->cv); + free(model->wv); *model = (lb_model_t) {0}; diff --git a/src/map.c b/src/map.c index ff30a96ab..5488c33cb 100644 --- a/src/map.c +++ b/src/map.c @@ -58,7 +58,7 @@ int map_create(pe_t * pe, cs_t * cs, const map_options_t * options, err: - if (obj) free(obj); + free(obj); return -1; } @@ -215,8 +215,8 @@ int map_initialise(pe_t * pe, cs_t * cs, const map_options_t * options, /* All failures are before any device memory is involved ... */ if (map->input.cs) io_metadata_finalise(&map->input); if (map->output.cs) io_metadata_finalise(&map->output); - if (map->data) free(map->data); - if (map->status) free(map->status); + free(map->data); + free(map->status); *map = (map_t) {0}; @@ -257,8 +257,8 @@ int map_finalise(map_t * map) { io_metadata_finalise(&map->input); io_metadata_finalise(&map->output); - if (map->data) free(map->data); - if (map->status) free(map->status); + free(map->data); + free(map->status); *map = (map_t) {0}; diff --git a/src/noise.c b/src/noise.c index 1bb58df1a..9ff4ff27b 100644 --- a/src/noise.c +++ b/src/noise.c @@ -67,7 +67,7 @@ int noise_create(pe_t * pe, cs_t * cs, const noise_options_t * options, return 0; err: - if (obj) free(obj); + free(obj); return -1; } @@ -259,7 +259,7 @@ int noise_finalise(noise_t * ns) { if (ns->output.cs) io_metadata_finalise(&ns->output); if (ns->input.cs) io_metadata_finalise(&ns->input); - if (ns->state) free(ns->state); + free(ns->state); *ns = (noise_t) {}; diff --git a/src/phi_force_stress.c b/src/phi_force_stress.c index b67ce7902..ca6941f2c 100644 --- a/src/phi_force_stress.c +++ b/src/phi_force_stress.c @@ -112,7 +112,7 @@ __host__ int pth_free(pth_t * pth) { tdpAssert( tdpFree(pth->target) ); } - if (pth->str) free(pth->str); + free(pth->str); free(pth); return 0; diff --git a/src/psi.c b/src/psi.c index 887a1a2bc..11e303db2 100644 --- a/src/psi.c +++ b/src/psi.c @@ -9,7 +9,7 @@ * Edinburgh Soft Matter and Statistical Physics Group and * Edinburgh Parallel Computing Centre * - * (c) 2012-2023 The University of Edinburgh + * (c) 2012-2024 The University of Edinburgh * * Contributing authors: * Kevin Stratford (kevin@epcc.ed.ac.uk) @@ -42,13 +42,13 @@ int psi_create(pe_t * pe, cs_t * cs, const psi_options_t * opts, ifail = psi_initialise(pe, cs, opts, psi); if (ifail != 0) goto err; - + *pobj = psi; return 0; err: - if (psi) free(psi); + free(psi); return -1; } @@ -169,7 +169,7 @@ int psi_halo_psi(psi_t * psi) { assert(psi); - /* Fudge device implmentation at the moment */ + /* Fudge device implementation at the moment */ field_memcpy(psi->psi, tdpMemcpyHostToDevice); field_halo(psi->psi); field_memcpy(psi->psi, tdpMemcpyDeviceToHost); @@ -588,7 +588,7 @@ int psi_zero_mean(psi_t * psi) { cs_ltot(psi->cs, ltot); cs_nhalo(psi->cs, &nhalo); - cs_nlocal(psi->cs, nlocal); + cs_nlocal(psi->cs, nlocal); cs_cart_comm(psi->cs, &comm); sum_local = 0.0; @@ -681,7 +681,7 @@ int psi_halo_psijump(psi_t * psi) { /* Borrow fluid site ic = 1 */ index1 = cs_index(psi->cs, 1, jc, kc); psidata[addr_rank0(psi->nsites, index)] = - psidata[addr_rank0(psi->nsites, index1)]; + psidata[addr_rank0(psi->nsites, index1)]; } } } @@ -705,11 +705,11 @@ int psi_halo_psijump(psi_t * psi) { /* Borrow fluid site at end ... */ index1 = cs_index(psi->cs, nlocal[X], jc, kc); psidata[addr_rank0(psi->nsites, index)] = - psidata[addr_rank0(psi->nsites, index1)]; + psidata[addr_rank0(psi->nsites, index1)]; } } } - } + } } if (mpicoords[Y] == 0) { @@ -728,11 +728,11 @@ int psi_halo_psijump(psi_t * psi) { /* Not periodic ... just borrow from fluid site jc = 1 */ index1 = cs_index(psi->cs, ic, 1, kc); psidata[addr_rank0(psi->nsites, index)] = - psidata[addr_rank0(psi->nsites, index1)]; + psidata[addr_rank0(psi->nsites, index1)]; } } } - } + } } @@ -752,11 +752,11 @@ int psi_halo_psijump(psi_t * psi) { /* Borrow fluid site at end */ index1 = cs_index(psi->cs, ic, nlocal[Y], kc); psidata[addr_rank0(psi->nsites, index)] = - psidata[addr_rank0(psi->nsites, index1)]; + psidata[addr_rank0(psi->nsites, index1)]; } } } - } + } } @@ -776,11 +776,11 @@ int psi_halo_psijump(psi_t * psi) { /* Borrow fluid site kc = 1 */ index1 = cs_index(psi->cs, ic, jc, 1); psidata[addr_rank0(psi->nsites, index)] = - psidata[addr_rank0(psi->nsites, index1)]; + psidata[addr_rank0(psi->nsites, index1)]; } } } - } + } } @@ -800,11 +800,11 @@ int psi_halo_psijump(psi_t * psi) { /* Borrow fluid site at end ... */ index1 = cs_index(psi->cs, ic, jc, nlocal[Z]); psidata[addr_rank0(psi->nsites, index)] = - psidata[addr_rank0(psi->nsites, index1)]; + psidata[addr_rank0(psi->nsites, index1)]; } } } - } + } } @@ -862,8 +862,8 @@ int psi_output_step(psi_t * psi, int its) { * To ensure overall electroneutrality, we consider the following: * * (1) assume surface charges have been assigned - * (2) assume the fluid is initialised with the backgound charge density - * of the electrolyte + * (2) assume the fluid is initialised with the background charge density + * of the electrolyte * (3) assume some number of colloids has been initialised, each * with a given charge. * diff --git a/src/stencil_d3q19.c b/src/stencil_d3q19.c index 49bcb38db..adc0b50bf 100644 --- a/src/stencil_d3q19.c +++ b/src/stencil_d3q19.c @@ -6,7 +6,7 @@ * Edinburgh Soft Matter and Statistical Physics Group and * Edinburgh Parallel Computing Centre * - * (c) 2023 The University of Edinburgh + * (c) 2023-2024 The University of Edinburgh * * Kevin Stratford (kevin@epcc.ed.ac.uk) * @@ -69,9 +69,10 @@ int stencil_d3q19_create(stencil_t ** stencil) { err: - if (s->wgradients) free(s->wgradients); - if (s->wlaplacian) free(s->wlaplacian); - if (s->cv) free(s->cv); + free(s->wgradients); + free(s->wlaplacian); + free(s->cv); + free(s); *stencil = NULL; diff --git a/src/stencil_d3q27.c b/src/stencil_d3q27.c index 6a0eb7556..3b7c4323f 100644 --- a/src/stencil_d3q27.c +++ b/src/stencil_d3q27.c @@ -8,7 +8,7 @@ * Edinburgh Soft Matter and Statistical Physics Group and * Edinburgh Parallel Computing Centre * - * (c) 2023 The University of Edinburgh + * (c) 2023-2024 The University of Edinburgh * * Kevin Stratford (kevin@epcc.ed.ac.uk) * @@ -74,9 +74,10 @@ int stencil_d3q27_create(stencil_t ** stencil) { err: - if (s->wgradients) free(s->wgradients); - if (s->wlaplacian) free(s->wlaplacian); - if (s->cv) free(s->cv); + free(s->wgradients); + free(s->wlaplacian); + free(s->cv); + free(s); *stencil = NULL; diff --git a/src/stencil_d3q7.c b/src/stencil_d3q7.c index 9497fa1f1..744c51be6 100644 --- a/src/stencil_d3q7.c +++ b/src/stencil_d3q7.c @@ -8,7 +8,7 @@ * Edinburgh Soft Matter and Statistical Physics Group and * Edinburgh Parallel Computing Centre * - * (c) 2023 The University of Edinburgh + * (c) 2023-2024 The University of Edinburgh * * Kevin Stratford (kevin@epcc.ed.ac.uk) * @@ -77,9 +77,10 @@ int stencil_d3q7_create(stencil_t ** stencil) { err: - if (s->wgradients) free(s->wgradients); - if (s->wlaplacian) free(s->wlaplacian); - if (s->cv) free(s->cv); + free(s->wgradients); + free(s->wlaplacian); + free(s->cv); + free(s); *stencil = NULL; diff --git a/src/wall.c b/src/wall.c index 70b945d5a..12ce8fe36 100644 --- a/src/wall.c +++ b/src/wall.c @@ -155,14 +155,15 @@ __host__ int wall_free(wall_t * wall) { free(wall->param); /* slip quantities */ - if (wall->linkk) free(wall->linkk); - if (wall->linkq) free(wall->linkq); - if (wall->links) free(wall->links); - - if (wall->linki) free(wall->linki); - if (wall->linkj) free(wall->linkj); - if (wall->linkp) free(wall->linkp); - if (wall->linku) free(wall->linku); + + free(wall->linkk); + free(wall->linkq); + free(wall->links); + + free(wall->linki); + free(wall->linkj); + free(wall->linkp); + free(wall->linku); free(wall);