Skip to content

Commit

Permalink
Code quality updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinstratford committed Dec 24, 2024
1 parent f525628 commit 2f7b7a1
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 65 deletions.
6 changes: 4 additions & 2 deletions src/colloids.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 6 additions & 3 deletions src/fe_electro.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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__
Expand Down
4 changes: 3 additions & 1 deletion src/field.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions src/field_grad.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/io_aggregator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([email protected])
*
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/io_impl_mpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/io_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int io_metadata_create(cs_t * cs,

err:

if (meta) free(meta);
free(meta);
return -1;
}

Expand Down
8 changes: 4 additions & 4 deletions src/lb_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([email protected])
Expand Down Expand Up @@ -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};

Expand Down
10 changes: 5 additions & 5 deletions src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -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};

Expand Down
4 changes: 2 additions & 2 deletions src/noise.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {};

Expand Down
2 changes: 1 addition & 1 deletion src/phi_force_stress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 18 additions & 18 deletions src/psi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([email protected])
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)];
}
}
}
Expand All @@ -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) {
Expand All @@ -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)];
}
}
}
}
}

}

Expand All @@ -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)];
}
}
}
}
}

}

Expand All @@ -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)];
}
}
}
}
}

}

Expand All @@ -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)];
}
}
}
}
}

}

Expand Down Expand Up @@ -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.
*
Expand Down
9 changes: 5 additions & 4 deletions src/stencil_d3q19.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([email protected])
*
Expand Down Expand Up @@ -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;

Expand Down
9 changes: 5 additions & 4 deletions src/stencil_d3q27.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([email protected])
*
Expand Down Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 2f7b7a1

Please sign in to comment.