Skip to content

Commit c847a64

Browse files
committed
Merge remote-tracking branch 'origin/master' into master
2 parents 7d9e3a0 + 6c6b5c2 commit c847a64

File tree

7 files changed

+83
-133
lines changed

7 files changed

+83
-133
lines changed

.github/workflows/cloud_parcel.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: cloud-parcel
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v1
12+
- name: Build the testing docker image
13+
run: docker build -f Dockerfile.cloud_parcel -t partmc-cloud-parcel .
14+
- name: Run the tests in the docker container
15+
run: docker run -t partmc-cloud-parcel bash -c 'cd /build; make test'

CMakeLists.txt

+2-37
Original file line numberDiff line numberDiff line change
@@ -103,30 +103,6 @@ endif()
103103
# SUNDIALS
104104

105105
if(ENABLE_SUNDIALS)
106-
find_path(SUITE_SPARSE_INCLUDE_DIR klu.h
107-
DOC "SuiteSparse include directory (must have klu.h)"
108-
PATHS $ENV{SUITE_SPARSE_HOME}/include $ENV{SUNDIALS_HOME}/include
109-
/opt/local/include /usr/local/include)
110-
find_library(SUITE_SPARSE_KLU_LIB klu
111-
DOC "SuiteSparse klu library"
112-
PATHS $ENV{SUITE_SPARSE_HOME}/lib $ENV{SUNDIALS_HOME}/lib
113-
/opt/local/lib /usr/local/lib)
114-
find_library(SUITE_SPARSE_AMD_LIB amd
115-
DOC "SuiteSparse amd library"
116-
PATHS $ENV{SUITE_SPARSE_HOME}/lib $ENV{SUNDIALS_HOME}/lib
117-
/opt/local/lib /usr/local/lib)
118-
find_library(SUITE_SPARSE_BTF_LIB btf
119-
DOC "SuiteSparse btf library"
120-
PATHS $ENV{SUITE_SPARSE_HOME}/lib $ENV{SUNDIALS_HOME}/lib
121-
/opt/local/lib /usr/local/lib)
122-
find_library(SUITE_SPARSE_COLAMD_LIB colamd
123-
DOC "SuiteSparse colamd library"
124-
PATHS $ENV{SUITE_SPARSE_HOME}/lib $ENV{SUNDIALS_HOME}/lib
125-
/opt/local/lib /usr/local/lib)
126-
find_library(SUITE_SPARSE_CONFIG_LIB suitesparseconfig
127-
DOC "SuiteSparse config library"
128-
PATHS $ENV{SUITE_SPARSE_HOME}/lib $ENV{SUNDIALS_HOME}/lib
129-
/opt/local/lib /usr/local/lib)
130106
find_path(SUNDIALS_INCLUDE_DIR cvode/cvode.h
131107
DOC "SUNDIALS include directory (must have cvode/, sundials/, nvector/ subdirs)"
132108
PATHS $ENV{SUNDIALS_HOME}/include /opt/local/include /usr/local/include)
@@ -136,20 +112,9 @@ if(ENABLE_SUNDIALS)
136112
find_library(SUNDIALS_CVODE_LIB sundials_cvode
137113
DOC "SUNDIALS CVODE library"
138114
PATHS $ENV{SUNDIALS_HOME}/lib /opt/local/lib /usr/local/lib)
139-
find_library(SUNDIALS_KLU_LIB sundials_sunlinsolklu
140-
DOC "SUNDIALS KLU library"
141-
PATHS $ENV{SUITE_SPARSE_HOME}/lib $ENV{SUNDIALS_HOME}/lib
142-
/opt/local/lib /usr/local/lib)
143-
find_library(SUNDIALS_SUNMATRIX_SPARSE_LIB sundials_sunmatrixsparse
144-
DOC "SUNDIALS SUNMatrixSparse library"
145-
PATHS $ENV{SUITE_SPARSE_HOME}/lib $ENV{SUNDIALS_HOME}/lib
146-
/opt/local/lib /usr/local/lib)
147-
set(SUNDIALS_LIBS ${SUNDIALS_NVECSERIAL_LIB} ${SUNDIALS_CVODE_LIB}
148-
${SUNDIALS_KLU_LIB} ${SUNDIALS_SUNMATRIX_SPARSE_LIB} ${SUITE_SPARSE_KLU_LIB}
149-
${SUITE_SPARSE_COLAMD_LIB} ${SUITE_SPARSE_AMD_LIB} ${SUITE_SPARSE_BTF_LIB}
150-
${SUITE_SPARSE_CONFIG_LIB})
115+
set(SUNDIALS_LIBS ${SUNDIALS_NVECSERIAL_LIB} ${SUNDIALS_CVODE_LIB})
151116
set(SUNDIALS_SRC src/condense_solver.c)
152-
include_directories(${SUNDIALS_INCLUDE_DIR} ${SUITE_SPARSE_INCLUDE_DIR})
117+
include_directories(${SUNDIALS_INCLUDE_DIR})
153118
add_definitions(-DPMC_USE_SUNDIALS)
154119
endif()
155120

Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ RUN dnf -y update \
77
gcc-gfortran \
88
make \
99
netcdf-fortran-devel \
10-
sundials-devel \
1110
gsl-devel \
1211
cmake \
1312
&& dnf clean all

Dockerfile.cloud_parcel

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM fedora:33
2+
3+
RUN dnf -y update \
4+
&& dnf -y install \
5+
gcc-gfortran \
6+
make \
7+
netcdf-fortran-devel \
8+
sundials-devel \
9+
gsl-devel \
10+
cmake \
11+
&& dnf clean all
12+
13+
# NOTE: Modify .dockerignore to whitelist files/directories to copy.
14+
COPY . /partmc/
15+
16+
RUN mkdir /build \
17+
&& cd /build \
18+
&& cmake -D CMAKE_BUILD_TYPE=release \
19+
-D CMAKE_C_FLAGS_RELEASE="-O2 -g -Werror -Wall -Wextra" \
20+
-D CMAKE_Fortran_FLAGS_RELEASE="-O2 -g -Werror -fimplicit-none -Wall -Wextra -Wconversion -Wunderflow -Wimplicit-interface -Wno-compare-reals -Wno-unused -Wno-unused-parameter -Wno-unused-dummy-argument -fbounds-check" \
21+
-D ENABLE_GSL:BOOL=TRUE \
22+
-D ENABLE_SUNDIALS:BOOL=TRUE \
23+
/partmc \
24+
&& make

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PartMC
44

55
PartMC: Particle-resolved Monte Carlo code for atmospheric aerosol simulation
66

7-
[![Latest version](https://img.shields.io/github/tag/compdyn/partmc.svg?label=version)](https://github.com/compdyn/partmc/blob/master/ChangeLog.md) [![GitHub build](https://img.shields.io/github/workflow/status/compdyn/partmc/CI.svg)](https://github.com/compdyn/partmc/actions) [![License](https://img.shields.io/github/license/compdyn/partmc.svg)](https://github.com/compdyn/partmc/blob/master/COPYING) [![DOI](https://zenodo.org/badge/24058992.svg)](https://zenodo.org/badge/latestdoi/24058992)
7+
[![Latest version](https://img.shields.io/github/tag/compdyn/partmc.svg?label=version)](https://github.com/compdyn/partmc/blob/master/ChangeLog.md) [![Docker build status](https://img.shields.io/docker/automated/compdyn/partmc.svg)](https://hub.docker.com/r/compdyn/partmc/builds/) [![Github Actions Status](https://github.com/compdyn/partmc/workflows/CI/badge.svg?branch=master)](https://github.com/compdyn/partmc/actions/workflows/main.yml) [![License](https://img.shields.io/github/license/compdyn/partmc.svg)](https://github.com/compdyn/partmc/blob/master/COPYING) [![DOI](https://zenodo.org/badge/24058992.svg)](https://zenodo.org/badge/latestdoi/24058992)
88

99
Version 2.6.0
1010
Released 2021-11-03
@@ -170,7 +170,7 @@ Optional dependencies:
170170
* MPI parallel support - <http://www.open-mpi.org/>
171171
* GSL for random number generators -
172172
<http://www.gnu.org/software/gsl/>
173-
* SUNDIALS ODE solver version 2.6 for condensation support -
173+
* SUNDIALS ODE solver for condensation support -
174174
<http://www.llnl.gov/casc/sundials/>
175175
* gnuplot for testcase plotting - <http://www.gnuplot.info/>
176176

src/condense.F90

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
!!
2323
!! The SUNDIALS ODE solver is used to compute the system evolution
2424
!! using an implicit method. The system Jacobian is explicitly
25-
!! inverveted as its structure is very simple.
25+
!! inverted as its structure is very simple.
2626
!!
2727
!! All equations used in this file are written in detail in the file
2828
!! \c doc/condense.tex.

src/condense_solver.c

+39-92
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <cvode/cvode.h>
1313
#include <nvector/nvector_serial.h>
1414
#include <sundials/sundials_types.h>
15-
#include <cvode/cvode_impl.h>
15+
#include <sunlinsol/sunlinsol_spgmr.h>
1616

1717
/** \brief Result code indicating successful completion.
1818
*/
@@ -38,25 +38,31 @@
3838
/** \brief Result code indicating failure of the solver.
3939
*/
4040
#define PMC_CONDENSE_SOLVER_FAIL 7
41+
/** \brief Result code indicating failure in creation of the linear solver.
42+
*/
43+
#define PMC_CONDENSE_SOLVER_LINSOL_CTOR 8
44+
/** \brief Result code indicating failure in setting the linear solver.
45+
*/
46+
#define PMC_CONDENSE_SOLVER_LINSOL_SET 9
47+
/** \brief Result code indicating failure in setting the preconditioner.
48+
*/
49+
#define PMC_CONDENSE_SOLVER_LINSOL_PREC 10
4150

4251
static int condense_vf(realtype t, N_Vector y, N_Vector ydot, void *user_data);
4352

4453
static int condense_check_flag(void *flagvalue, char *funcname, int opt);
4554

4655
/*******************************************************/
4756
// solver block
48-
static int condense_solver_Init(CVodeMem cv_mem);
49-
50-
static int condense_solver_Setup(CVodeMem cv_mem, int convfail, N_Vector ypred,
51-
N_Vector fpred, booleantype *jcurPtr,
52-
N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3);
5357

54-
static int condense_solver_Solve(CVodeMem cv_mem, N_Vector b, N_Vector weight,
55-
N_Vector ycur, N_Vector fcur);
58+
static int condense_solver_Solve(double t, N_Vector ycur, N_Vector fcur,
59+
N_Vector r, N_Vector b, double gamma, double delta, int lr, void *user_data);
5660

57-
static void condense_solver_Free(CVodeMem cv_mem);
5861
/*******************************************************/
5962

63+
void condense_vf_f(int neq, realtype t, double *y_f, double *ydot_f);
64+
void condense_jac_solve_f(int neq, double t, double *ycur_f, double *fcur_f, double *b_f, double gamma);
65+
6066
/** \brief Call the ODE solver.
6167
*
6268
* \param neq The number of equations.
@@ -73,11 +79,10 @@ static void condense_solver_Free(CVodeMem cv_mem);
7379
int condense_solver(int neq, double *x_f, double *abstol_f, double reltol_f,
7480
double t_initial_f, double t_final_f)
7581
{
76-
realtype reltol, t_initial, t_final, t, tout;
82+
realtype reltol, t_initial, t_final, t;
7783
N_Vector y, abstol;
7884
void *cvode_mem;
79-
CVodeMem cv_mem;
80-
int flag, i, pretype, maxl;
85+
int flag, i;
8186
realtype *y_data, *abstol_data;
8287

8388
y = abstol = NULL;
@@ -102,7 +107,7 @@ int condense_solver(int neq, double *x_f, double *abstol_f, double reltol_f,
102107
t_initial = t_initial_f;
103108
t_final = t_final_f;
104109

105-
cvode_mem = CVodeCreate(CV_BDF, CV_NEWTON);
110+
cvode_mem = CVodeCreate(CV_BDF);
106111
if (condense_check_flag((void *)cvode_mem, "CVodeCreate", 0))
107112
return PMC_CONDENSE_SOLVER_INIT_CVODE_MEM;
108113

@@ -118,34 +123,16 @@ int condense_solver(int neq, double *x_f, double *abstol_f, double reltol_f,
118123
if (condense_check_flag(&flag, "CVodeSetMaxNumSteps", 1))
119124
return PMC_CONDENSE_SOLVER_SET_MAX_STEPS;
120125

121-
/*******************************************************/
122-
// dense solver
123-
//flag = CVDense(cvode_mem, neq);
124-
//if (condense_check_flag(&flag, "CVDense", 1)) return(1);
125-
/*******************************************************/
126-
127-
/*******************************************************/
128-
// iterative solver
129-
//pretype = PREC_LEFT;
130-
//maxl = 0;
131-
//flag = CVSptfqmr(cvode_mem, pretype, maxl);
132-
//if (condense_check_flag(&flag, "CVSptfqmr", 1)) return(1);
133-
134-
//flag = CVSpilsSetJacTimesVecFn(cvode_mem, condense_jtimes);
135-
//if (condense_check_flag(&flag, "CVSpilsSetJacTimesVecFn", 1)) return(1);
136-
137-
//flag = CVSpilsSetPreconditioner(cvode_mem, NULL, condense_prec);
138-
//if (condense_check_flag(&flag, "CVSpilsSetPreconditioner", 1)) return(1);
139-
/*******************************************************/
140-
141-
/*******************************************************/
142-
// explicit solver
143-
cv_mem = (CVodeMem)cvode_mem;
144-
cv_mem->cv_linit = condense_solver_Init;
145-
cv_mem->cv_lsetup = condense_solver_Setup;
146-
cv_mem->cv_lsolve = condense_solver_Solve;
147-
cv_mem->cv_lfree = condense_solver_Free;
148-
/*******************************************************/
126+
127+
SUNLinearSolver LS = SUNLinSol_SPGMR(y, PREC_LEFT, 0);
128+
if (condense_check_flag((void *)LS, "SUNLinSol_SPGMR", 0))
129+
return PMC_CONDENSE_SOLVER_LINSOL_CTOR;
130+
flag = CVodeSetLinearSolver(cvode_mem, LS, NULL);
131+
if (condense_check_flag(&flag, "CVodeSetLinearSolver", 1))
132+
return PMC_CONDENSE_SOLVER_LINSOL_SET;
133+
flag = CVodeSetPreconditioner(cvode_mem, NULL, condense_solver_Solve);
134+
if (condense_check_flag(&flag, "CVodeSetPreconditioner", 1))
135+
return PMC_CONDENSE_SOLVER_LINSOL_PREC;
149136

150137
t = t_initial;
151138
flag = CVode(cvode_mem, t_final, y, &t, CV_NORMAL);
@@ -170,6 +157,8 @@ int condense_solver(int neq, double *x_f, double *abstol_f, double reltol_f,
170157
* \param user_data A pointer to user-provided data.
171158
* \return A result code (0 is success).
172159
*/
160+
#pragma GCC diagnostic push
161+
#pragma GCC diagnostic ignored "-Wunused-parameter"
173162
static int condense_vf(realtype t, N_Vector y, N_Vector ydot, void *user_data)
174163
{
175164
realtype *y_data, *ydot_data;
@@ -195,6 +184,7 @@ static int condense_vf(realtype t, N_Vector y, N_Vector ydot, void *user_data)
195184
free(ydot_f);
196185
return(0);
197186
}
187+
#pragma GCC diagnostic pop
198188

199189
/** \brief Check the return value from a SUNDIALS call.
200190
*
@@ -243,88 +233,45 @@ static int condense_check_flag(void *flagvalue, char *funcname, int opt)
243233
return(0);
244234
}
245235

246-
/** \brief Initialization routine for the ODE linear equation solver.
247-
*
248-
* \param cv_mem The \c CVODE solver parameter structure.
249-
* \return A result code (0 is success).
250-
*/
251-
static int condense_solver_Init(CVodeMem cv_mem)
252-
{
253-
return(0);
254-
}
255-
256-
/** \brief Setup routine for the ODE linear equation solver.
257-
*
258-
* \param cv_mem The \c CVODE solver parameter structure.
259-
* \param convfail
260-
* \param ypred
261-
* \param fpred
262-
* \param jcurPtr
263-
* \param vtemp1
264-
* \param vtemp2
265-
* \param vtemp3
266-
* \return A result code (0 is success).
267-
*/
268-
static int condense_solver_Setup(CVodeMem cv_mem, int convfail, N_Vector ypred,
269-
N_Vector fpred, booleantype *jcurPtr,
270-
N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3)
271-
{
272-
return(0);
273-
}
274-
275236
/** \brief Linear solver routine for use by the ODE solver.
276237
*
277238
* Should solve the system \f$(I - \gamma J) x = b\f$, where \f$J\f$
278239
* is the current vector field Jacobian, \f$\gamma\f$ is a given
279240
* scalar, and \f$b\f$ is a given vector.
280241
*
281-
* \param cv_mem The \c CVODE solver parameter structure.
282-
* \param b The right-hand-side of the linear system.
283-
* \param weight
284-
* \param ycur The current state vector.
285-
* \param fcur The current vector field vector.
286-
* \return A result code (0 is success).
287242
*/
288-
static int condense_solver_Solve(CVodeMem cv_mem, N_Vector b, N_Vector weight,
289-
N_Vector ycur, N_Vector fcur)
243+
#pragma GCC diagnostic push
244+
#pragma GCC diagnostic ignored "-Wunused-parameter"
245+
static int condense_solver_Solve(double t, N_Vector ycur, N_Vector fcur,
246+
N_Vector b, N_Vector z, double gamma, double delta, int lr, void *user_data)
290247
{
291-
realtype *b_data, *ycur_data, *fcur_data;
248+
realtype *b_data, *ycur_data, *fcur_data, *z_data;
292249
int i, neq;
293250
double *b_f, *ycur_f, *fcur_f;
294-
double t, gamma;
295251

296252
neq = NV_LENGTH_S(b);
297253
b_data = NV_DATA_S(b);
254+
z_data = NV_DATA_S(z);
298255
ycur_data = NV_DATA_S(ycur);
299256
fcur_data = NV_DATA_S(fcur);
300257

301258
b_f = malloc(neq * sizeof(double));
302259
ycur_f = malloc(neq * sizeof(double));
303260
fcur_f = malloc(neq * sizeof(double));
304261

305-
t = cv_mem->cv_tn;
306-
gamma = cv_mem->cv_gamma;
307-
308262
for (i = 0; i < neq; i++) {
309263
b_f[i] = b_data[i];
310264
ycur_f[i] = ycur_data[i];
311265
fcur_f[i] = fcur_data[i];
312266
}
313267
condense_jac_solve_f(neq, t, ycur_f, fcur_f, b_f, gamma);
314268
for (i = 0; i < neq; i++) {
315-
b_data[i] = b_f[i];
269+
z_data[i] = b_f[i];
316270
}
317271

318272
free(b_f);
319273
free(ycur_f);
320274
free(fcur_f);
321275
return(0);
322276
}
323-
324-
/** \brief Finalization routine for the ODE linear equation solver.
325-
*
326-
* \param cv_mem The \c CVODE solver parameter structure.
327-
*/
328-
static void condense_solver_Free(CVodeMem cv_mem)
329-
{
330-
}
277+
#pragma GCC diagnostic pop

0 commit comments

Comments
 (0)