Skip to content
Snippets Groups Projects
Commit 7b9e2e84 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Merge branch 'master' into gizmo_cosmology_theory

parents c89f1411 d4421028
Branches
Tags
1 merge request!590Added derivation of comoving Euler equations to cosmology theory document.
Showing with 1916 additions and 143 deletions
*~
*.hdf5
*.dirstamp
Makefile
Makefile.in
......@@ -44,12 +45,16 @@ examples/*/restart/*
examples/*/*/used_parameters.yml
examples/*/err_file*
examples/*/out_file*
examples/*/stf_output*
examples/*/stf_ouput*
examples/*/stf_*
examples/*/log*
examples/*/*/unused_parameters.yml
examples/*/*.mpg
examples/*/gravity_checks_*.dat
examples/*/coolingtables.tar.gz
examples/*/coolingtables
examples/CoolingRates/cooling_rates
examples/CoolingRates/cooling_element_*.dat
examples/CoolingRates/cooling_output.dat
tests/testActivePair
tests/testActivePair.sh
......@@ -63,12 +68,18 @@ tests/brute_force_perturbed.dat
tests/swift_dopair_perturbed.dat
tests/test27cells
tests/test27cells_subset
tests/test27cellsStars
tests/test27cellsStars_subset
tests/testPeriodicBC
tests/test125cells
tests/brute_force_27_standard.dat
tests/swift_dopair_27_standard.dat
tests/brute_force_27_perturbed.dat
tests/swift_dopair_27_perturbed.dat
tests/star_brute_force_27_standard.dat
tests/swift_star_dopair_27_standard.dat
tests/star_brute_force_27_perturbed.dat
tests/swift_star_dopair_27_perturbed.dat
tests/brute_force_125_standard.dat
tests/swift_dopair_125_standard.dat
tests/brute_force_125_perturbed.dat
......@@ -106,6 +117,8 @@ tests/testPeriodicBC.sh
tests/testPeriodicBCPerturbed.sh
tests/test27cells.sh
tests/test27cellsPerturbed.sh
tests/test27cellsStars.sh
tests/test27cellsStarsPerturbed.sh
tests/test125cells.sh
tests/test125cellsPerturbed.sh
tests/testParser.sh
......@@ -131,7 +144,11 @@ tests/testEOS
tests/testEOS*.txt
tests/testEOS*.png
tests/testUtilities
tests/testCosmology
tests/testOutputList
tests/testCbrt
tests/testFormat.sh
tests/testCooling
theory/latex/swift.pdf
theory/SPH/Kernels/kernels.pdf
......@@ -148,6 +165,7 @@ theory/Multipoles/potential_long.pdf
theory/Multipoles/potential_short.pdf
theory/Multipoles/force_short.pdf
theory/Cosmology/cosmology.pdf
theory/Cooling/eagle_cooling.pdf
m4/libtool.m4
m4/ltoptions.m4
......@@ -165,6 +183,8 @@ m4/lt~obsolete.m4
/stamp-h1
/test-driver
src/equation_of_state/planetary/*.txt
# Intel compiler optimization reports
*.optrpt
......@@ -316,3 +336,6 @@ sympy-plots-for-*.tex/
#ctags
*tags
# vim
*.swp
......@@ -2,12 +2,14 @@ Pedro Gonnet gonnet@google.com
Matthieu Schaller matthieu.schaller@durham.ac.uk
Aidan Chalk aidan.chalk@durham.ac.uk
Peter W. Draper p.w.draper@durham.ac.uk
Bert Vandenbrouck bert.vandenbroucke@gmail.com
Bert Vandenbroucke bert.vandenbroucke@gmail.com
James S. Willis james.s.willis@durham.ac.uk
John A. Regan john.a.regan@durham.ac.uk
Angus Lepper angus.lepper@ed.ac.uk
Tom Theuns tom.theuns@durham.ac.uk
Richard G. Bower r.g.bower@durham.ac.uk
Stefan Arridge stefan.arridge@durham.ac.uk
Massimiliano Culpo massimiliano.culpo@googlemail.com
Josh Borrow joshua.borrow@durham.ac.uk
Loic Hausammann loic.hausammann@epfl.ch
Yves Revaz yves.revaz@epfl.ch
Jacob Kegerreis jacob.kegerreis@durham.ac.uk
......@@ -19,7 +19,10 @@
ACLOCAL_AMFLAGS = -I m4
# Show the way...
SUBDIRS = src examples doc tests
SUBDIRS = src argparse examples doc tests tools
if HAVEEAGLECOOLING
SUBDIRS += examples/CoolingRates
endif
# Non-standard files that should be part of the distribution.
EXTRA_DIST = INSTALL.swift .clang-format format.sh
Welcome to the cosmological hydrodynamical code
______ _________________
/ ___/ | / / _/ ___/_ __/
\__ \| | /| / // // /_ / /
___/ /| |/ |/ // // __/ / /
/____/ |__/|__/___/_/ /_/
\__ \| | /| / // // /_ / /
___/ /| |/ |/ // // __/ / /
/____/ |__/|__/___/_/ /_/
SPH With Inter-dependent Fine-grained Tasking
Website: www.swiftsim.com
Website: www.swiftsim.com
Twitter: @SwiftSimulation
See INSTALL.swift for install instructions.
Usage: swift [OPTION]... PARAMFILE
swift_mpi [OPTION]... PARAMFILE
Valid options are:
-a Pin runners using processor affinity.
-c Run with cosmological time integration.
-C Run with cooling.
-d Dry run. Read the parameter file, allocate memory but does not read
the particles from ICs and exit before the start of time integration.
Allows user to check validity of parameter and IC files as well as memory limits.
-D Always drift all particles even the ones far from active particles. This emulates
Gadget-[23] and GIZMO's default behaviours.
-e Enable floating-point exceptions (debugging mode).
-f {int} Overwrite the CPU frequency (Hz) to be used for time measurements.
-g Run with an external gravitational potential.
-G Run with self-gravity.
-M Reconstruct the multipoles every time-step.
-n {int} Execute a fixed number of time steps. When unset use the time_end parameter to stop.
-P {sec:par:val} Set parameter value and overwrites values read from the parameters file. Can be used more than once.
-s Run with hydrodynamics.
-S Run with stars.
-t {int} The number of threads to use on each MPI rank. Defaults to 1 if not specified.
-T Print timers every time-step.
-v [12] Increase the level of verbosity:
1: MPI-rank 0 writes,
2: All MPI-ranks write.
-y {int} Time-step frequency at which task graphs are dumped.
-Y {int} Time-step frequency at which threadpool tasks are dumped.
-h Print this help message and exit.
See the file parameter_example.yml for an example of parameter file.
Usage: swift [options] [[--] param-file]
or: swift [options] param-file
or: swift_mpi [options] [[--] param-file]
or: swift_mpi [options] param-file
Parameters:
-h, --help show this help message and exit
Simulation options:
-b, --feedback Run with stars feedback
-c, --cosmology Run with cosmological time integration.
-C, --cooling Run with cooling
-D, --drift-all Always drift all particles even the ones
far from active particles. This emulates
Gadget-[23] and GIZMO's default behaviours.
-F, --sourceterms
-g, --external-gravity Run with an external gravitational potential.
-G, --self-gravity Run with self-gravity.
-M, --multipole-reconstruction Reconstruct the multipoles every time-step.
-s, --hydro Run with hydrodynamics.
-S, --stars Run with stars
-x, --velociraptor Run with structure finding
Control options:
-a, --pin Pin runners using processor affinity.
-d, --dry-run Dry run. Read the parameter file, allocates
memory but does not read the particles
from ICs. Exits before the start of time
integration. Checks the validity of
parameters and IC files as well as memory
limits.
-e, --fpe Enable floating-point exceptions (debugging
mode).
-f, --cpu-frequency=<str> Overwrite the CPU frequency (Hz) to be
used for time measurements.
-n, --steps=<int> Execute a fixed number of time steps.
When unset use the time_end parameter
to stop.
-o, --output-params=<str> Generate a default output parameter
file.
-P, --param=<str> Set parameter value, overiding the value
read from the parameter file. Can be used
more than once {sec:par:value}.
-r, --restart Continue using restart files.
-t, --threads=<int> The number of threads to use on each MPI
rank. Defaults to 1 if not specified.
-T, --timers=<int> Print timers every time-step.
-v, --verbose=<int> Run in verbose mode, in MPI mode 2 outputs
from all ranks.
-y, --task-dumps=<int> Time-step frequency at which task graphs
are dumped.
-Y, --threadpool-dumps=<int> Time-step frequency at which threadpool
tasks are dumped.
See the file examples/parameter_example.yml for an example of parameter file.
......@@ -49,9 +49,9 @@ are highly encouraged.
Welcome to the cosmological hydrodynamical code
______ _________________
/ ___/ | / / _/ ___/_ __/
\__ \| | /| / // // /_ / /
___/ /| |/ |/ // // __/ / /
/____/ |__/|__/___/_/ /_/
\__ \| | /| / // // /_ / /
___/ /| |/ |/ // // __/ / /
/____/ |__/|__/___/_/ /_/
SPH With Inter-dependent Fine-grained Tasking
Website: www.swiftsim.com
......@@ -59,35 +59,59 @@ are highly encouraged.
See INSTALL.swift for install instructions.
Usage: swift [OPTION]... PARAMFILE
swift_mpi [OPTION]... PARAMFILE
Valid options are:
-a Pin runners using processor affinity.
-c Run with cosmological time integration.
-C Run with cooling.
-d Dry run. Read the parameter file, allocate memory but does not read
the particles from ICs and exit before the start of time integration.
Allows user to check validity of parameter and IC files as well as memory limits.
-D Always drift all particles even the ones far from active particles. This emulates
Gadget-[23] and GIZMO's default behaviours.
-e Enable floating-point exceptions (debugging mode).
-f {int} Overwrite the CPU frequency (Hz) to be used for time measurements.
-g Run with an external gravitational potential.
-G Run with self-gravity.
-M Reconstruct the multipoles every time-step.
-n {int} Execute a fixed number of time steps. When unset use the time_end parameter to stop.
-P {sec:par:val} Set parameter value and overwrites values read from the parameters file. Can be used more than once.
-s Run with hydrodynamics.
-S Run with stars.
-t {int} The number of threads to use on each MPI rank. Defaults to 1 if not specified.
-T Print timers every time-step.
-v [12] Increase the level of verbosity:
1: MPI-rank 0 writes,
2: All MPI-ranks write.
-y {int} Time-step frequency at which task graphs are dumped.
-Y {int} Time-step frequency at which threadpool tasks are dumped.
-h Print this help message and exit.
Usage: swift [options] [[--] param-file]
or: swift [options] param-file
or: swift_mpi [options] [[--] param-file]
or: swift_mpi [options] param-file
Parameters:
-h, --help show this help message and exit
Simulation options:
-b, --feedback Run with stars feedback
-c, --cosmology Run with cosmological time integration.
-C, --cooling Run with cooling
-D, --drift-all Always drift all particles even the ones
far from active particles. This emulates
Gadget-[23] and GIZMO's default behaviours.
-F, --sourceterms
-g, --external-gravity Run with an external gravitational potential.
-G, --self-gravity Run with self-gravity.
-M, --multipole-reconstruction Reconstruct the multipoles every time-step.
-s, --hydro Run with hydrodynamics.
-S, --stars Run with stars
-x, --velociraptor Run with structure finding
Control options:
-a, --pin Pin runners using processor affinity.
-d, --dry-run Dry run. Read the parameter file, allocates
memory but does not read the particles
from ICs. Exits before the start of time
integration. Checks the validity of
parameters and IC files as well as memory
limits.
-e, --fpe Enable floating-point exceptions (debugging
mode).
-f, --cpu-frequency=<str> Overwrite the CPU frequency (Hz) to be
used for time measurements.
-n, --steps=<int> Execute a fixed number of time steps.
When unset use the time_end parameter
to stop.
-o, --output-params=<str> Generate a default output parameter
file.
-P, --param=<str> Set parameter value, overiding the value
read from the parameter file. Can be used
more than once {sec:par:value}.
-r, --restart Continue using restart files.
-t, --threads=<int> The number of threads to use on each MPI
rank. Defaults to 1 if not specified.
-T, --timers=<int> Print timers every time-step.
-v, --verbose=<int> Run in verbose mode, in MPI mode 2 outputs
from all ranks.
-y, --task-dumps=<int> Time-step frequency at which task graphs
are dumped.
-Y, --threadpool-dumps=<int> Time-step frequency at which threadpool
tasks are dumped.
See the file examples/parameter_example.yml for an example of parameter file.
```
# FAQs
## Why removing parsed command-line switches/options?
It destroys the original `argv` array, not compatible with other arguments parsing
library.
This is because this library is used for short-lived programs, e.g. cli tools
at beginning. It's very convenient to process remain arguments if we remove
parsed command-line arguments, e.g. `<comamnd> [-[s]|--switch]... arguments`.
If you want keep original `argc/argv`, you can make a copy, then pass them to
`argparse_parse`, e.g.
```c
int copy_argc = argc;
const char **copy_argv = argv;
copy_argv = malloc(copy_argc * sizeof(char *));
for (int i = 0; i < argc; i++) {
copy_argv[i] = (char *)argv[i];
}
argparse_parse(&argparse, copy_argc, copy_argv);
```
Issues:
- https://github.com/cofyc/argparse/issues/3
- https://github.com/cofyc/argparse/issues/9
## Why using `intptr_t` to hold associated data? Why not `void *`?
I choose `intptr_t` because it's a integer type which also can be used to hold
a pointer value. Most of the time, we only need a integer to hold
user-provided value, see `OPT_BIT` as example. If you want to provide a pointer
which points to a large amount of data, you can cast it to `intptr_t` and cast
it back to original pointer in callback function.
The MIT License (MIT)
Copyright (c) 2012-2013 Yecheng Fu <cofyc.jackson@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# This file is part of SWIFT.
# Copyright (c) 2018 Peter W. Draper (p.w.draper@durham.ac.uk)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
lib_LTLIBRARIES = libargparse.la
include_HEADERS = argparse.h
AM_SOURCES = argparse.c
# Sources and flags for regular library
libargparse_la_SOURCES = $(AM_SOURCES)
libargparse_la_CFLAGS = $(AM_CFLAGS)
libargparse_la_LDFLAGS = $(AM_LDFLAGS)
EXTRA_DIST = LICENSE README.md
approvers:
- cofyc
# argparse [![Build Status](https://travis-ci.org/cofyc/argparse.png)](https://travis-ci.org/cofyc/argparse)
argparse - A command line arguments parsing library in C (compatible with C++).
## Description
This module is inspired by parse-options.c (git) and python's argparse
module.
Arguments parsing is common task in cli program, but traditional `getopt`
libraries are not easy to use. This library provides high-level arguments
parsing solutions.
The program defines what arguments it requires, and `argparse` will figure
out how to parse those out of `argc` and `argv`, it also automatically
generates help and usage messages and issues errors when users give the
program invalid arguments.
## Features
- handles both optional and positional arguments
- produces highly informative usage messages
- issues errors when given invalid arguments
There are basically three types of options:
- boolean options
- options with mandatory argument
- options with optional argument
There are basically two forms of options:
- short option consist of one dash (`-`) and one alphanumeric character.
- long option begin with two dashes (`--`) and some alphanumeric characters.
Short options may be bundled, e.g. `-a -b` can be specified as `-ab`.
Options are case-sensitive.
Options and non-option arguments can clearly be separated using the `--` option.
## Examples
```c
#include "argparse.h"
static const char *const usage[] = {
"test_argparse [options] [[--] args]",
"test_argparse [options]",
NULL,
};
#define PERM_READ (1<<0)
#define PERM_WRITE (1<<1)
#define PERM_EXEC (1<<2)
int
main(int argc, const char **argv)
{
int force = 0;
int test = 0;
int num = 0;
const char *path = NULL;
int perms = 0;
struct argparse_option options[] = {
OPT_HELP(),
OPT_GROUP("Basic options"),
OPT_BOOLEAN('f', "force", &force, "force to do"),
OPT_BOOLEAN('t', "test", &test, "test only"),
OPT_STRING('p', "path", &path, "path to read"),
OPT_INTEGER('n', "num", &num, "selected num"),
OPT_GROUP("Bits options"),
OPT_BIT(0, "read", &perms, "read perm", NULL, PERM_READ, OPT_NONEG),
OPT_BIT(0, "write", &perms, "write perm", NULL, PERM_WRITE),
OPT_BIT(0, "exec", &perms, "exec perm", NULL, PERM_EXEC),
OPT_END(),
};
struct argparse argparse;
argparse_init(&argparse, options, usage, 0);
argparse_describe(&argparse, "\nA brief description of what the program does and how it works.", "\nAdditional description of the program after the description of the arguments.");
argc = argparse_parse(&argparse, argc, argv);
if (force != 0)
printf("force: %d\n", force);
if (test != 0)
printf("test: %d\n", test);
if (path != NULL)
printf("path: %s\n", path);
if (num != 0)
printf("num: %d\n", num);
if (argc != 0) {
printf("argc: %d\n", argc);
int i;
for (i = 0; i < argc; i++) {
printf("argv[%d]: %s\n", i, *(argv + i));
}
}
if (perms) {
printf("perms: %d\n", perms);
}
return 0;
}
```
/**
* Copyright (C) 2012-2015 Yecheng Fu <cofyc.jackson at gmail dot com>
* All rights reserved.
*
* Use of this source code is governed by a MIT-style license that can be found
* in the LICENSE file.
*/
#include "argparse.h"
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define OPT_UNSET 1
#define OPT_LONG (1 << 1)
static const char *prefix_skip(const char *str, const char *prefix) {
size_t len = strlen(prefix);
return strncmp(str, prefix, len) ? NULL : str + len;
}
static int prefix_cmp(const char *str, const char *prefix) {
for (;; str++, prefix++)
if (!*prefix) {
return 0;
} else if (*str != *prefix) {
return (unsigned char)*prefix - (unsigned char)*str;
}
}
static void argparse_error(struct argparse *self,
const struct argparse_option *opt,
const char *reason, int flags) {
(void)self;
if (flags & OPT_LONG) {
fprintf(stderr, "error: option `--%s` %s\n", opt->long_name, reason);
} else {
fprintf(stderr, "error: option `-%c` %s\n", opt->short_name, reason);
}
exit(1);
}
static int argparse_getvalue(struct argparse *self,
const struct argparse_option *opt, int flags) {
const char *s = NULL;
if (!opt->value) goto skipped;
switch (opt->type) {
case ARGPARSE_OPT_BOOLEAN:
if (flags & OPT_UNSET) {
*(int *)opt->value = *(int *)opt->value - 1;
} else {
*(int *)opt->value = *(int *)opt->value + 1;
}
if (*(int *)opt->value < 0) {
*(int *)opt->value = 0;
}
break;
case ARGPARSE_OPT_BIT:
if (flags & OPT_UNSET) {
*(int *)opt->value &= ~opt->data;
} else {
*(int *)opt->value |= opt->data;
}
break;
case ARGPARSE_OPT_STRING:
if (self->optvalue) {
*(const char **)opt->value = self->optvalue;
self->optvalue = NULL;
} else if (self->argc > 1) {
self->argc--;
*(const char **)opt->value = *++self->argv;
} else {
argparse_error(self, opt, "requires a value", flags);
}
break;
case ARGPARSE_OPT_INTEGER:
errno = 0;
if (self->optvalue) {
*(int *)opt->value = strtol(self->optvalue, (char **)&s, 0);
self->optvalue = NULL;
} else if (self->argc > 1) {
self->argc--;
*(int *)opt->value = strtol(*++self->argv, (char **)&s, 0);
} else {
argparse_error(self, opt, "requires a value", flags);
}
if (errno) argparse_error(self, opt, strerror(errno), flags);
if (s[0] != '\0')
argparse_error(self, opt, "expects an integer value", flags);
break;
case ARGPARSE_OPT_FLOAT:
errno = 0;
if (self->optvalue) {
*(float *)opt->value = strtof(self->optvalue, (char **)&s);
self->optvalue = NULL;
} else if (self->argc > 1) {
self->argc--;
*(float *)opt->value = strtof(*++self->argv, (char **)&s);
} else {
argparse_error(self, opt, "requires a value", flags);
}
if (errno) argparse_error(self, opt, strerror(errno), flags);
if (s[0] != '\0')
argparse_error(self, opt, "expects a numerical value", flags);
break;
default:
assert(0);
}
skipped:
if (opt->callback) {
return opt->callback(self, opt);
}
return 0;
}
static void argparse_options_check(const struct argparse_option *options) {
for (; options->type != ARGPARSE_OPT_END; options++) {
switch (options->type) {
case ARGPARSE_OPT_END:
case ARGPARSE_OPT_BOOLEAN:
case ARGPARSE_OPT_BIT:
case ARGPARSE_OPT_INTEGER:
case ARGPARSE_OPT_FLOAT:
case ARGPARSE_OPT_STRING:
case ARGPARSE_OPT_GROUP:
continue;
default:
fprintf(stderr, "wrong option type: %d", options->type);
break;
}
}
}
static int argparse_short_opt(struct argparse *self,
const struct argparse_option *options) {
for (; options->type != ARGPARSE_OPT_END; options++) {
if (options->short_name == *self->optvalue) {
self->optvalue = self->optvalue[1] ? self->optvalue + 1 : NULL;
return argparse_getvalue(self, options, 0);
}
}
return -2;
}
static int argparse_long_opt(struct argparse *self,
const struct argparse_option *options) {
for (; options->type != ARGPARSE_OPT_END; options++) {
const char *rest;
int opt_flags = 0;
if (!options->long_name) continue;
rest = prefix_skip(self->argv[0] + 2, options->long_name);
if (!rest) {
// negation disabled?
if (options->flags & OPT_NONEG) {
continue;
}
// only OPT_BOOLEAN/OPT_BIT supports negation
if (options->type != ARGPARSE_OPT_BOOLEAN &&
options->type != ARGPARSE_OPT_BIT) {
continue;
}
if (prefix_cmp(self->argv[0] + 2, "no-")) {
continue;
}
rest = prefix_skip(self->argv[0] + 2 + 3, options->long_name);
if (!rest) continue;
opt_flags |= OPT_UNSET;
}
if (*rest) {
if (*rest != '=') continue;
self->optvalue = rest + 1;
}
return argparse_getvalue(self, options, opt_flags | OPT_LONG);
}
return -2;
}
int argparse_init(struct argparse *self, struct argparse_option *options,
const char *const *usages, int flags) {
memset(self, 0, sizeof(*self));
self->options = options;
self->usages = usages;
self->flags = flags;
self->description = NULL;
self->epilog = NULL;
return 0;
}
void argparse_describe(struct argparse *self, const char *description,
const char *epilog) {
self->description = description;
self->epilog = epilog;
}
int argparse_parse(struct argparse *self, int argc, const char **argv) {
self->argc = argc - 1;
self->argv = argv + 1;
self->out = argv;
argparse_options_check(self->options);
for (; self->argc; self->argc--, self->argv++) {
const char *arg = self->argv[0];
if (arg[0] != '-' || !arg[1]) {
if (self->flags & ARGPARSE_STOP_AT_NON_OPTION) {
goto end;
}
// if it's not option or is a single char '-', copy verbatim
self->out[self->cpidx++] = self->argv[0];
continue;
}
// short option
if (arg[1] != '-') {
self->optvalue = arg + 1;
switch (argparse_short_opt(self, self->options)) {
case -1:
break;
case -2:
goto unknown;
}
while (self->optvalue) {
switch (argparse_short_opt(self, self->options)) {
case -1:
break;
case -2:
goto unknown;
}
}
continue;
}
// if '--' presents
if (!arg[2]) {
self->argc--;
self->argv++;
break;
}
// long option
switch (argparse_long_opt(self, self->options)) {
case -1:
break;
case -2:
goto unknown;
}
continue;
unknown:
fprintf(stderr, "error: unknown option `%s`\n", self->argv[0]);
argparse_usage(self);
exit(1);
}
end:
memmove(self->out + self->cpidx, self->argv, self->argc * sizeof(*self->out));
self->out[self->cpidx + self->argc] = NULL;
return self->cpidx + self->argc;
}
void argparse_usage(struct argparse *self) {
if (self->usages) {
fprintf(stdout, "Usage: %s\n", *self->usages++);
while (*self->usages && **self->usages)
fprintf(stdout, " or: %s\n", *self->usages++);
} else {
fprintf(stdout, "Usage:\n");
}
// print description
if (self->description) fprintf(stdout, "%s\n", self->description);
fputc('\n', stdout);
const struct argparse_option *options;
// figure out best width
size_t usage_opts_width = 0;
size_t len;
options = self->options;
for (; options->type != ARGPARSE_OPT_END; options++) {
len = 0;
if ((options)->short_name) {
len += 2;
}
if ((options)->short_name && (options)->long_name) {
len += 2; // separator ", "
}
if ((options)->long_name) {
len += strlen((options)->long_name) + 2;
}
if (options->type == ARGPARSE_OPT_INTEGER) {
len += strlen("=<int>");
}
if (options->type == ARGPARSE_OPT_FLOAT) {
len += strlen("=<flt>");
} else if (options->type == ARGPARSE_OPT_STRING) {
len += strlen("=<str>");
}
len = (len + 3) - ((len + 3) & 3);
if (usage_opts_width < len) {
usage_opts_width = len;
}
}
usage_opts_width += 4; // 4 spaces prefix
options = self->options;
for (; options->type != ARGPARSE_OPT_END; options++) {
size_t pos = 0;
int pad = 0;
if (options->type == ARGPARSE_OPT_GROUP) {
fputc('\n', stdout);
fprintf(stdout, "%s", options->help);
fputc('\n', stdout);
continue;
}
pos = fprintf(stdout, " ");
if (options->short_name) {
pos += fprintf(stdout, "-%c", options->short_name);
}
if (options->long_name && options->short_name) {
pos += fprintf(stdout, ", ");
}
if (options->long_name) {
pos += fprintf(stdout, "--%s", options->long_name);
}
if (options->type == ARGPARSE_OPT_INTEGER) {
pos += fprintf(stdout, "=<int>");
}
if (options->type == ARGPARSE_OPT_FLOAT) {
pos += fprintf(stdout, "=<flt>");
} else if (options->type == ARGPARSE_OPT_STRING) {
pos += fprintf(stdout, "=<str>");
}
if (pos <= usage_opts_width) {
pad = usage_opts_width - pos;
} else {
fputc('\n', stdout);
pad = usage_opts_width;
}
if (options->help != NULL && strlen(options->help) > 0) {
char *str = strdup(options->help);
char *token = strtok(str, " ");
fprintf(stdout, "%*s%s ", pad + 2, "", token);
int count = strlen(token);
int dangling = 1;
while ((token = strtok(NULL, " ")) != NULL) {
if (count == 0) {
fprintf(stdout, "%*s", (int)pos + pad + 2, "");
dangling = 1;
}
printf("%s ", token);
count += strlen(token);
if (count > 30) {
count = 0;
fprintf(stdout, "\n");
dangling = 0;
}
}
if (dangling) fprintf(stdout, "\n");
free(str);
} else {
fprintf(stdout, "\n");
}
}
// print epilog
if (self->epilog) fprintf(stdout, "%s\n", self->epilog);
}
int argparse_help_cb(struct argparse *self,
const struct argparse_option *option) {
(void)option;
argparse_usage(self);
exit(0);
}
/**
* Copyright (C) 2012-2015 Yecheng Fu <cofyc.jackson at gmail dot com>
* All rights reserved.
*
* Use of this source code is governed by a MIT-style license that can be found
* in the LICENSE file.
*/
#ifndef ARGPARSE_H
#define ARGPARSE_H
/* For c++ compatibility */
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
struct argparse;
struct argparse_option;
typedef int argparse_callback(struct argparse *self,
const struct argparse_option *option);
enum argparse_flag {
ARGPARSE_STOP_AT_NON_OPTION = 1,
};
enum argparse_option_type {
/* special */
ARGPARSE_OPT_END,
ARGPARSE_OPT_GROUP,
/* options with no arguments */
ARGPARSE_OPT_BOOLEAN,
ARGPARSE_OPT_BIT,
/* options with arguments (optional or required) */
ARGPARSE_OPT_INTEGER,
ARGPARSE_OPT_FLOAT,
ARGPARSE_OPT_STRING,
};
enum argparse_option_flags {
OPT_NONEG = 1, /* disable negation */
};
/**
* argparse option
*
* `type`:
* holds the type of the option, you must have an ARGPARSE_OPT_END last in
* your array.
*
* `short_name`:
* the character to use as a short option name, '\0' if none.
*
* `long_name`:
* the long option name, without the leading dash, NULL if none.
*
* `value`:
* stores pointer to the value to be filled.
*
* `help`:
* the short help message associated to what the option does.
* Must never be NULL (except for ARGPARSE_OPT_END).
*
* `callback`:
* function is called when corresponding argument is parsed.
*
* `data`:
* associated data. Callbacks can use it like they want.
*
* `flags`:
* option flags.
*/
struct argparse_option {
enum argparse_option_type type;
const char short_name;
const char *long_name;
void *value;
const char *help;
argparse_callback *callback;
intptr_t data;
int flags;
};
/**
* argpparse
*/
struct argparse {
// user supplied
const struct argparse_option *options;
const char *const *usages;
int flags;
const char *description; // a description after usage
const char *epilog; // a description at the end
// internal context
int argc;
const char **argv;
const char **out;
int cpidx;
const char *optvalue; // current option value
};
// built-in callbacks
int argparse_help_cb(struct argparse *self,
const struct argparse_option *option);
// built-in option macros
#define OPT_END() \
{ ARGPARSE_OPT_END, 0, NULL, NULL, 0, NULL, 0, 0 }
#define OPT_BOOLEAN(...) \
{ ARGPARSE_OPT_BOOLEAN, __VA_ARGS__ }
#define OPT_BIT(...) \
{ ARGPARSE_OPT_BIT, __VA_ARGS__ }
#define OPT_INTEGER(...) \
{ ARGPARSE_OPT_INTEGER, __VA_ARGS__ }
#define OPT_FLOAT(...) \
{ ARGPARSE_OPT_FLOAT, __VA_ARGS__ }
#define OPT_STRING(...) \
{ ARGPARSE_OPT_STRING, __VA_ARGS__ }
#define OPT_GROUP(h) \
{ ARGPARSE_OPT_GROUP, 0, NULL, NULL, h, NULL, 0, 0 }
#define OPT_HELP() \
OPT_BOOLEAN('h', "help", NULL, "show this help message and exit", \
argparse_help_cb, 0, 0)
int argparse_init(struct argparse *self, struct argparse_option *options,
const char *const *usages, int flags);
void argparse_describe(struct argparse *self, const char *description,
const char *epilog);
int argparse_parse(struct argparse *self, int argc, const char **argv);
void argparse_usage(struct argparse *self);
#ifdef __cplusplus
}
#endif
#endif
#!/bin/bash
_version='1.02'
_plan_set=0
_no_plan=0
_skip_all=0
_test_died=0
_expected_tests=0
_executed_tests=0
_failed_tests=0
TODO=
usage(){
cat <<'USAGE'
tap-functions: A TAP-producing BASH library
PLAN:
plan_no_plan
plan_skip_all [REASON]
plan_tests NB_TESTS
TEST:
ok RESULT [NAME]
okx COMMAND
is RESULT EXPECTED [NAME]
isnt RESULT EXPECTED [NAME]
like RESULT PATTERN [NAME]
unlike RESULT PATTERN [NAME]
pass [NAME]
fail [NAME]
SKIP:
skip [CONDITION] [REASON] [NB_TESTS=1]
skip $feature_not_present "feature not present" 2 || {
is $a "a"
is $b "b"
}
TODO:
Specify TODO mode by setting $TODO:
TODO="not implemented yet"
ok $result "some not implemented test"
unset TODO
OTHER:
diag MSG
EXAMPLE:
#!/bin/bash
. tap-functions
plan_tests 7
me=$USER
is $USER $me "I am myself"
like $HOME $me "My home is mine"
like "`id`" $me "My id matches myself"
/bin/ls $HOME 1>&2
ok $? "/bin/ls $HOME"
# Same thing using okx shortcut
okx /bin/ls $HOME
[[ "`id -u`" != "0" ]]
i_am_not_root=$?
skip $i_am_not_root "Must be root" || {
okx ls /root
}
TODO="figure out how to become root..."
okx [ "$HOME" == "/root" ]
unset TODO
USAGE
exit
}
opt=
set_u=
while getopts ":sx" opt ; do
case $_opt in
u) set_u=1 ;;
*) usage ;;
esac
done
shift $(( OPTIND - 1 ))
# Don't allow uninitialized variables if requested
[[ -n "$set_u" ]] && set -u
unset opt set_u
# Used to call _cleanup on shell exit
trap _exit EXIT
plan_no_plan(){
(( _plan_set != 0 )) && "You tried to plan twice!"
_plan_set=1
_no_plan=1
return 0
}
plan_skip_all(){
local reason=${1:-''}
(( _plan_set != 0 )) && _die "You tried to plan twice!"
_print_plan 0 "Skip $reason"
_skip_all=1
_plan_set=1
_exit 0
return 0
}
plan_tests(){
local tests=${1:?}
(( _plan_set != 0 )) && _die "You tried to plan twice!"
(( tests == 0 )) && _die "You said to run 0 tests! You've got to run something."
_print_plan $tests
_expected_tests=$tests
_plan_set=1
return $tests
}
_print_plan(){
local tests=${1:?}
local directive=${2:-''}
echo -n "1..$tests"
[[ -n "$directive" ]] && echo -n " # $directive"
echo
}
pass(){
local name=$1
ok 0 "$name"
}
fail(){
local name=$1
ok 1 "$name"
}
# This is the workhorse method that actually
# prints the tests result.
ok(){
local result=${1:?}
local name=${2:-''}
(( _plan_set == 0 )) && _die "You tried to run a test without a plan! Gotta have a plan."
_executed_tests=$(( $_executed_tests + 1 ))
if [[ -n "$name" ]] ; then
if _matches "$name" "^[0-9]+$" ; then
diag " You named your test '$name'. You shouldn't use numbers for your test names."
diag " Very confusing."
fi
fi
if (( result != 0 )) ; then
echo -n "not "
_failed_tests=$(( _failed_tests + 1 ))
fi
echo -n "ok $_executed_tests"
if [[ -n "$name" ]] ; then
local ename=${name//\#/\\#}
echo -n " - $ename"
fi
if [[ -n "$TODO" ]] ; then
echo -n " # TODO $TODO" ;
if (( result != 0 )) ; then
_failed_tests=$(( _failed_tests - 1 ))
fi
fi
echo
if (( result != 0 )) ; then
local file='tap-functions'
local func=
local line=
local i=0
local bt=$(caller $i)
while _matches "$bt" "tap-functions$" ; do
i=$(( $i + 1 ))
bt=$(caller $i)
done
local backtrace=
eval $(caller $i | (read line func file ; echo "backtrace=\"$file:$func() at line $line.\""))
local t=
[[ -n "$TODO" ]] && t="(TODO) "
if [[ -n "$name" ]] ; then
diag " Failed ${t}test '$name'"
diag " in $backtrace"
else
diag " Failed ${t}test in $backtrace"
fi
fi
return $result
}
okx(){
local command="$@"
local line=
diag "Output of '$command':"
$command | while read line ; do
diag "$line"
done
ok ${PIPESTATUS[0]} "$command"
}
_equals(){
local result=${1:?}
local expected=${2:?}
if [[ "$result" == "$expected" ]] ; then
return 0
else
return 1
fi
}
# Thanks to Aaron Kangas for the patch to allow regexp matching
# under bash < 3.
_bash_major_version=${BASH_VERSION%%.*}
_matches(){
local result=${1:?}
local pattern=${2:?}
if [[ -z "$result" || -z "$pattern" ]] ; then
return 1
else
if (( _bash_major_version >= 3 )) ; then
eval '[[ "$result" =~ "$pattern" ]]'
else
echo "$result" | egrep -q "$pattern"
fi
fi
}
_is_diag(){
local result=${1:?}
local expected=${2:?}
diag " got: '$result'"
diag " expected: '$expected'"
}
is(){
local result=${1:?}
local expected=${2:?}
local name=${3:-''}
_equals "$result" "$expected"
(( $? == 0 ))
ok $? "$name"
local r=$?
(( r != 0 )) && _is_diag "$result" "$expected"
return $r
}
isnt(){
local result=${1:?}
local expected=${2:?}
local name=${3:-''}
_equals "$result" "$expected"
(( $? != 0 ))
ok $? "$name"
local r=$?
(( r != 0 )) && _is_diag "$result" "$expected"
return $r
}
like(){
local result=${1:?}
local pattern=${2:?}
local name=${3:-''}
_matches "$result" "$pattern"
(( $? == 0 ))
ok $? "$name"
local r=$?
(( r != 0 )) && diag " '$result' doesn't match '$pattern'"
return $r
}
unlike(){
local result=${1:?}
local pattern=${2:?}
local name=${3:-''}
_matches "$result" "$pattern"
(( $? != 0 ))
ok $? "$name"
local r=$?
(( r != 0 )) && diag " '$result' matches '$pattern'"
return $r
}
skip(){
local condition=${1:?}
local reason=${2:-''}
local n=${3:-1}
if (( condition == 0 )) ; then
local i=
for (( i=0 ; i<$n ; i++ )) ; do
_executed_tests=$(( _executed_tests + 1 ))
echo "ok $_executed_tests # skip: $reason"
done
return 0
else
return
fi
}
diag(){
local msg=${1:?}
if [[ -n "$msg" ]] ; then
echo "# $msg"
fi
return 1
}
_die(){
local reason=${1:-'<unspecified error>'}
echo "$reason" >&2
_test_died=1
_exit 255
}
BAIL_OUT(){
local reason=${1:-''}
echo "Bail out! $reason" >&2
_exit 255
}
_cleanup(){
local rc=0
if (( _plan_set == 0 )) ; then
diag "Looks like your test died before it could output anything."
return $rc
fi
if (( _test_died != 0 )) ; then
diag "Looks like your test died just after $_executed_tests."
return $rc
fi
if (( _skip_all == 0 && _no_plan != 0 )) ; then
_print_plan $_executed_tests
fi
local s=
if (( _no_plan == 0 && _expected_tests < _executed_tests )) ; then
s= ; (( _expected_tests > 1 )) && s=s
local extra=$(( _executed_tests - _expected_tests ))
diag "Looks like you planned $_expected_tests test$s but ran $extra extra."
rc=-1 ;
fi
if (( _no_plan == 0 && _expected_tests > _executed_tests )) ; then
s= ; (( _expected_tests > 1 )) && s=s
diag "Looks like you planned $_expected_tests test$s but only ran $_executed_tests."
fi
if (( _failed_tests > 0 )) ; then
s= ; (( _failed_tests > 1 )) && s=s
diag "Looks like you failed $_failed_tests test$s of $_executed_tests."
fi
return $rc
}
_exit_status(){
if (( _no_plan != 0 || _plan_set == 0 )) ; then
return $_failed_tests
fi
if (( _expected_tests < _executed_tests )) ; then
return $(( _executed_tests - _expected_tests ))
fi
return $(( _failed_tests + ( _expected_tests - _executed_tests )))
}
_exit(){
local rc=${1:-''}
if [[ -z "$rc" ]] ; then
_exit_status
rc=$?
fi
_cleanup
local alt_rc=$?
(( alt_rc != 0 )) && rc=$alt_rc
trap - EXIT
exit $rc
}
#!/bin/bash
. tap-functions
plan_no_plan
is "$(./test_argparse -f --path=/path/to/file a 2>&1)" 'force: 1
path: /path/to/file
argc: 1
argv[0]: a'
is "$(./test_argparse -f -f --force --no-force 2>&1)" 'force: 2'
is "$(./test_argparse -i 2>&1)" 'error: option `-i` requires a value'
is "$(./test_argparse -i 2 2>&1)" 'int_num: 2'
is "$(./test_argparse -i2 2>&1)" 'int_num: 2'
is "$(./test_argparse -ia 2>&1)" 'error: option `-i` expects an integer value'
is "$(./test_argparse -i 0xFFFFFFFFFFFFFFFFF 2>&1)" \
'error: option `-i` Numerical result out of range'
is "$(./test_argparse -s 2.4 2>&1)" 'flt_num: 2.4'
is "$(./test_argparse -s2.4 2>&1)" 'flt_num: 2.4'
is "$(./test_argparse -sa 2>&1)" 'error: option `-s` expects a numerical value'
is "$(./test_argparse -s 1e999 2>&1)" \
'error: option `-s` Numerical result out of range'
is "$(./test_argparse -f -- do -f -h 2>&1)" 'force: 1
argc: 3
argv[0]: do
argv[1]: -f
argv[2]: -h'
is "$(./test_argparse -tf 2>&1)" 'force: 1
test: 1'
is "$(./test_argparse --read --write 2>&1)" 'perms: 3'
is "$(./test_argparse -h)" 'Usage: test_argparse [options] [[--] args]
or: test_argparse [options]
A brief description of what the program does and how it works.
-h, --help show this help message and exit
Basic options
-f, --force force to do
-t, --test test only
-p, --path=<str> path to read
-i, --int=<int> selected integer
-s, --float=<flt> selected float
Bits options
--read read perm
--write write perm
--exec exec perm
Additional description of the program after the description of the arguments.'
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "argparse.h"
static const char *const usages[] = {
"test_argparse [options] [[--] args]",
"test_argparse [options]",
NULL,
};
#define PERM_READ (1 << 0)
#define PERM_WRITE (1 << 1)
#define PERM_EXEC (1 << 2)
struct stuff {
const char *path[10];
int npath;
};
static int callback(struct argparse *self, const struct argparse_option *opt) {
printf("Called back... %s\n", *(char **)opt->value);
struct stuff *data = (struct stuff *)opt->data;
data->path[data->npath] = *(char **)opt->value;
data->npath++;
return 1;
}
int main(int argc, const char **argv) {
int force = 0;
int self_gravity = 0;
int int_num = 0;
float flt_num = 0.f;
struct stuff data;
data.npath = 0;
data.path[0] = NULL;
const char *buffer;
int perms = 0;
int npath;
struct argparse_option options[] = {
OPT_HELP(),
OPT_GROUP("Basic options"),
OPT_BOOLEAN('f', "force", &force, "force to do", NULL, 0, 0),
OPT_BOOLEAN(0, "self-gravity", &self_gravity, "use self gravity", NULL, 0,
0),
OPT_STRING('P', "path", &buffer, "path to read", &callback,
(intptr_t)&data, 0),
OPT_INTEGER('i', "int", &int_num, "selected integer", NULL, 0, 0),
OPT_FLOAT('s', "float", &flt_num, "selected float", NULL, 0, 0),
OPT_END(),
};
struct argparse argparse;
argparse_init(&argparse, options, usages, 0);
argparse_describe(
&argparse,
"\nA brief description of what the program does and how it works.",
"\nAdditional description of the program after the description of the "
"arguments.");
argc = argparse_parse(&argparse, argc, argv);
if (force != 0) printf("force: %d\n", force);
if (self_gravity != 0) printf("self_gravity: %d\n", self_gravity);
if (data.npath > 0) {
for (int i = 0; i < data.npath; i++) printf("path: %s\n", data.path[i]);
}
if (int_num != 0) printf("int_num: %d\n", int_num);
if (flt_num != 0) printf("flt_num: %g\n", flt_num);
if (argc != 0) {
printf("argc: %d\n", argc);
int i;
for (i = 0; i < argc; i++) {
printf("argv[%d]: %s\n", i, *(argv + i));
}
}
if (perms) {
printf("perms: %d\n", perms);
}
return 0;
}
This diff is collapsed.
......@@ -761,11 +761,15 @@ WARN_LOGFILE =
INPUT = @top_srcdir@ @top_srcdir@/src @top_srcdir@/tests @top_srcdir@/examples
INPUT += @top_srcdir@/src/hydro/Minimal
INPUT += @top_srcdir@/src/hydro/Gadget2
INPUT += @top_srcdir@/src/gravity/Default
INPUT += @top_srcdir@/src/stars/Default
INPUT += @top_srcdir@/src/riemann
INPUT += @top_srcdir@/src/potential/point_mass
INPUT += @top_srcdir@/src/equation_of_state/ideal_gas
INPUT += @top_srcdir@/src/cooling/const_du
INPUT += @top_srcdir@/src/cooling/const_lambda
INPUT += @top_srcdir@/src/cooling/Compton
INPUT += @top_srcdir@/src/cooling/EAGLE
INPUT += @top_srcdir@/src/chemistry/EAGLE
......
.. Command line options
Matthieu Schaller, 21st October 2018
.. _cmdline-options:
Command line options
====================
SWIFT requires a number of runtime options to run and get any sensible output.
For instance, just running the ``swift`` binary will not use any SPH or gravity;
the particles will just sit still!
Below is a list of the command line options and when they should be used. The same list
can be found by typing ``./swift -h``::
-h, --help show this help message and exit
Simulation options:
-b, --feedback Run with stars feedback
-c, --cosmology Run with cosmological time integration.
-C, --cooling Run with cooling
-D, --drift-all Always drift all particles even the ones
far from active particles. This emulates
Gadget-[23] and GIZMO's default behaviours.
-F, --sourceterms
-g, --external-gravity Run with an external gravitational potential.
-G, --self-gravity Run with self-gravity.
-M, --multipole-reconstruction Reconstruct the multipoles every time-step.
-s, --hydro Run with hydrodynamics.
-S, --stars Run with stars
-x, --velociraptor Run with structure finding
Control options:
-a, --pin Pin runners using processor affinity.
-d, --dry-run Dry run. Read the parameter file, allocates
memory but does not read the particles
from ICs. Exits before the start of time
integration. Checks the validity of
parameters and IC files as well as memory
limits.
-e, --fpe Enable floating-point exceptions (debugging
mode).
-f, --cpu-frequency=<str> Overwrite the CPU frequency (Hz) to be
used for time measurements.
-n, --steps=<int> Execute a fixed number of time steps.
When unset use the time_end parameter
to stop.
-o, --output-params=<str> Generate a default output parameter
file.
-P, --param=<str> Set parameter value, overiding the value
read from the parameter file. Can be used
more than once {sec:par:value}.
-r, --restart Continue using restart files.
-t, --threads=<int> The number of threads to use on each MPI
rank. Defaults to 1 if not specified.
-T, --timers=<int> Print timers every time-step.
-v, --verbose=<int> Run in verbose mode, in MPI mode 2 outputs
from all ranks.
-y, --task-dumps=<int> Time-step frequency at which task graphs
are dumped.
-Y, --threadpool-dumps=<int> Time-step frequency at which threadpool
tasks are dumped.
......@@ -31,7 +31,7 @@ cooling contains a temperature floor avoiding negative temperature.
Grackle
~~~~~~~
Grackle is a chemistry and cooling library presented in B. Smith et al. 2016
Grackle is a chemistry and cooling library presented in `B. Smith et al. 2016 <https://arxiv.org/abs/1610.09591>`_
(do not forget to cite if used). Four different modes are available:
equilibrium, 6 species network (H, H\\( ^+ \\), e\\( ^- \\), He, He\\( ^+ \\)
and He\\( ^{++} \\)), 9 species network (adds H\\(^-\\), H\\(_2\\) and
......@@ -45,6 +45,19 @@ to provide an HDF5 table computed by Cloudy.
When starting a simulation without providing the different fractions, the code
supposes an equilibrium and computes the fractions automatically.
In order to compile SWIFT with Grackle, you need to provide the options ``with-grackle``
and ``with-chemistry``.
You will need a Grackle version later than 3.1. To compile it, run
the following commands from the root directory of Grackle:
``./configure; cd src/clib``.
Update the variables ``LOCAL_HDF5_INSTALL`` and ``MACH_INSTALL_PREFIX`` in
the file ``src/clib/Make.mach.linux-gnu``.
Finish with ``make machine-linux-gnu; make && make install``.
If you encounter any problem, you can look at the `Grackle documentation <https://grackle.readthedocs.io/en/latest/>`_
You can now provide the path given for ``MACH_INSTALL_PREFIX`` to ``with-grackle``.
Eagle
~~~~~
......@@ -53,7 +66,7 @@ TODO
How to Implement a New Cooling
------------------------------
The developper should provide at least one function for:
The developer should provide at least one function for:
* writing the cooling name in HDF5
* cooling a particle
* the maximal time step possible
......
.. External potentials in SWIFT
Folkert Nobels, 25th October 2018
External Potentials
===================
SWIFT can be run with an external potential on this page we will summarize the
current potentials which can be run with SWIFT and how to implement your own
potential in SWIFT.
Implemented External Potentials
-------------------------------
Currently there are several potentials implemented in SWIFT. On this page we
give a short overview of the potentials that are implemented in the code:
1. No potential (none)
2. Point mass potential (point-mass): classical point mass, can be placed at
a position with a mass.
3. Plummer potential (point-mass-softened): in the code a softened point mass
corresponds to a Plummer potential, can be placed at a position with a mass.
4. Isothermal potential (isothermal): An isothermal potential which corresponds
to a density profile which is :math:`\propto r^{-2}` and a potential which is
logarithmic. This potential has as free parameters the rotation velocity
and the position.
5. Hernquist potential (hernquist): A potential that is given by the Hernquist
potential:
:math:`\Phi(r) = - \frac{GM}{r+a}.`
The free parameters of Hernquist potential are mass, scale length,
and softening. The potential can be set at any position in the box.
6. NFW potential (nfw): The most used potential to describe dark matter halos, the
potential is given by:
:math:`\Phi(r) = - \frac{4\pi G \rho_0 R_s^3}{r} \ln \left( 1+
\frac{r}{R_s} \right).`
This potential has as free parameters the concentration of the DM halo, the
virial mass (:math:`M_{200}`) and the critical density.
7. Sine wave (sine-wave)
8. Point mass ring (point-mass-ring)
9. Disc Patch (disc-patch)
How to implement your own potential
-----------------------------------
The first step in implementing your own potential is making a directory of your
potential in the ``src/potential`` folder and creating a file in the folder
called ``potential.h``.
Configuring the potential
^^^^^^^^^^^^^^^^^^^^^^^^^
To get started you can copy a ``potential.h`` file from an already implemented
potential. In this potential the header guards (e.g. ``#IFDEF <>``) need to be
changed to the specific potential and the ``struct`` and
``potential_init_backend`` need to be changed such that it uses your potential
and reads the correct potential from the parameter file during running the
program.
Add the potential to the ``potential.h`` file in the ``src`` directory such that
the program knows that it is possible to run with this potential.
Furthermore during the configuration of the code it also needs to be clear for
the program that the code can be configured to run with the different
potentials. This means that the ``configure.ac`` file needs to be changed.
This can be done to add an other case in the potential::
case "$with_potential" in
none)
AC_DEFINE([EXTERNAL_POTENTIAL_NONE], [1], [No external potential])
;;
newpotential)
AC_DEFINE([EXTERNAL_POTENTIAL_NEWPOTENTIAL], [1], [New external potential])
;;
After this change it is possible to configure the code to use your new potential.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment