From 82d4f18f73dcadb19f9046e46a78951afffadbc9 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <matthieu.schaller@durham.ac.uk> Date: Mon, 5 Sep 2016 18:19:36 +0100 Subject: [PATCH] Fixed linking problem. Added cooling example to 'make dist'. Applied code formatting. --- examples/Makefile.am | 1 + examples/main.c | 2 +- src/Makefile.am | 6 ++-- src/cooling.c | 54 ++++++++++++++++++++++++++++++ src/cooling.h | 8 +++++ src/cooling/const_du/cooling.h | 9 +++-- src/cooling/const_lambda/cooling.h | 9 +++-- src/swift.h | 1 + 8 files changed, 77 insertions(+), 13 deletions(-) create mode 100644 src/cooling.c diff --git a/examples/Makefile.am b/examples/Makefile.am index 38ddcf6193..d9e1f2fe74 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -68,6 +68,7 @@ swift_fixdt_mpi_LDADD = ../src/.libs/libswiftsim_mpi.a $(MPI_LIBS) $(EXTRA_LIBS EXTRA_DIST = BigCosmoVolume/makeIC.py \ BigPerturbedBox/makeIC_fcc.py \ CosmoVolume/cosmoVolume.yml CosmoVolume/getIC.sh CosmoVolume/run.sh \ + CoolingBox/coolingBox.yml CoolingBox/energy_plot.py CoolingBox/makeIC.py CoolingBox/run.sh \ EAGLE_12/eagle_12.yml EAGLE_12/getIC.sh EAGLE_12/README EAGLE_12/run.sh \ EAGLE_25/eagle_25.yml EAGLE_25/getIC.sh EAGLE_25/README EAGLE_25/run.sh \ EAGLE_50/eagle_50.yml EAGLE_50/getIC.sh EAGLE_50/README EAGLE_50/run.sh \ diff --git a/examples/main.c b/examples/main.c index 14c95dd3ec..bcf90b5a95 100644 --- a/examples/main.c +++ b/examples/main.c @@ -442,7 +442,7 @@ int main(int argc, char *argv[]) { struct cooling_data cooling; if (with_cooling) cooling_init(params, &us, &prog_const, &cooling); if (with_cooling && myrank == 0) cooling_print(&cooling); - + /* Construct the engine policy */ int engine_policies = ENGINE_POLICY | engine_policy_steal; if (with_drift_all) engine_policies |= engine_policy_drift_all; diff --git a/src/Makefile.am b/src/Makefile.am index 84cfd823ad..2343ab99ff 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -45,13 +45,14 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \ physical_constants.h physical_constants_cgs.h potentials.h version.h \ hydro_properties.h threadpool.h cooling.h + # Common source files AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \ serial_io.c timers.c debug.c scheduler.c proxy.c parallel_io.c \ units.c common_io.c single_io.c multipole.c version.c map.c \ kernel_hydro.c tools.c part.c partition.c clocks.c parser.c \ physical_constants.c potentials.c hydro_properties.c \ - runner_doiact_fft.c threadpool.c + runner_doiact_fft.c threadpool.c cooling.c # Include files for distribution, not installation. nobase_noinst_HEADERS = approx_math.h atomic.h cycle.h error.h inline.h kernel_hydro.h kernel_gravity.h \ @@ -72,7 +73,8 @@ nobase_noinst_HEADERS = approx_math.h atomic.h cycle.h error.h inline.h kernel_h hydro/Gizmo/hydro_debug.h hydro/Gizmo/hydro_part.h \ riemann.h riemann/riemann_hllc.h riemann/riemann_trrs.h \ riemann/riemann_exact.h riemann/riemann_vacuum.h \ - cooling/const_du/cooling.h cooling/const_lambda/cooling.h + cooling/const_du/cooling.h cooling/const_lambda/cooling.h + # Sources and flags for regular library libswiftsim_la_SOURCES = $(AM_SOURCES) diff --git a/src/cooling.c b/src/cooling.c new file mode 100644 index 0000000000..102adba9d5 --- /dev/null +++ b/src/cooling.c @@ -0,0 +1,54 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk) + * + * This program 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. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + ******************************************************************************/ + +/* Config parameters. */ +#include "../config.h" + +/* This object's header. */ +#include "cooling.h" + +/** + * @brief Initialises the cooling properties. + * + * Calls cooling_init_backend for the chosen cooling function. + * + * @param parameter_file The parsed parameter file. + * @param us The current internal system of units. + * @param phys_const The physical constants in internal units. + * @param cooling The cooling properties to initialize + */ +void cooling_init(const struct swift_params* parameter_file, + const struct UnitSystem* us, + const struct phys_const* phys_const, + struct cooling_data* cooling) { + + cooling_init_backend(parameter_file, us, phys_const, cooling); +} + +/** + * @brief Prints the properties of the cooling model to stdout. + * + * Calls cooling_print_backend for the chosen cooling function. + * + * @param cooling The properties of the cooling function. + */ +void cooling_print(const struct cooling_data* cooling) { + + cooling_print_backend(cooling); +} diff --git a/src/cooling.h b/src/cooling.h index d2dac6a804..034ee2329d 100644 --- a/src/cooling.h +++ b/src/cooling.h @@ -41,4 +41,12 @@ #error "Invalid choice of cooling function." #endif +/* Common functions */ +void cooling_init(const struct swift_params* parameter_file, + const struct UnitSystem* us, + const struct phys_const* phys_const, + struct cooling_data* cooling); + +void cooling_print(const struct cooling_data* cooling); + #endif /* SWIFT_COOLING_H */ diff --git a/src/cooling/const_du/cooling.h b/src/cooling/const_du/cooling.h index 2c4f66d938..634723f5a5 100644 --- a/src/cooling/const_du/cooling.h +++ b/src/cooling/const_du/cooling.h @@ -113,10 +113,9 @@ __attribute__((always_inline)) INLINE static double cooling_timestep( * @param phys_const The physical constants in internal units. * @param cooling The cooling properties to initialize */ -INLINE void cooling_init(const struct swift_params* parameter_file, - const struct UnitSystem* us, - const struct phys_const* phys_const, - struct cooling_data* cooling) { +static INLINE void cooling_init_backend( + const struct swift_params* parameter_file, const struct UnitSystem* us, + const struct phys_const* phys_const, struct cooling_data* cooling) { cooling->cooling_rate = parser_get_param_double(parameter_file, "ConstCooling:cooling_rate"); @@ -131,7 +130,7 @@ INLINE void cooling_init(const struct swift_params* parameter_file, * * @param cooling The properties of the cooling function. */ -INLINE void cooling_print(const struct cooling_data* cooling) { +static INLINE void cooling_print_backend(const struct cooling_data* cooling) { message("Cooling function is 'Constant cooling' with rate %f and floor %f", cooling->cooling_rate, cooling->min_energy); diff --git a/src/cooling/const_lambda/cooling.h b/src/cooling/const_lambda/cooling.h index 407c7c2943..609d06a387 100644 --- a/src/cooling/const_lambda/cooling.h +++ b/src/cooling/const_lambda/cooling.h @@ -167,10 +167,9 @@ __attribute__((always_inline)) INLINE static float cooling_timestep( * @param phys_const The physical constants in internal units. * @param cooling The cooling properties to initialize */ -INLINE void cooling_init(const struct swift_params* parameter_file, - const struct UnitSystem* us, - const struct phys_const* phys_const, - struct cooling_data* cooling) { +static INLINE void cooling_init_backend( + const struct swift_params* parameter_file, const struct UnitSystem* us, + const struct phys_const* phys_const, struct cooling_data* cooling) { cooling->lambda = parser_get_param_double(parameter_file, "LambdaCooling:lambda"); @@ -200,7 +199,7 @@ INLINE void cooling_init(const struct swift_params* parameter_file, * * @param cooling The properties of the cooling function. */ -INLINE void cooling_print(const struct cooling_data* cooling) { +static INLINE void cooling_print_backend(const struct cooling_data* cooling) { message( "Cooling function is 'Constant lambda' with " diff --git a/src/swift.h b/src/swift.h index 7e3116c1de..80a4b1a1f7 100644 --- a/src/swift.h +++ b/src/swift.h @@ -27,6 +27,7 @@ #include "cell.h" #include "clocks.h" #include "const.h" +#include "cooling.h" #include "cycle.h" #include "debug.h" #include "engine.h" -- GitLab